Skip to content

Commit

Permalink
Add SAS token renewal
Browse files Browse the repository at this point in the history
  • Loading branch information
KaSroka committed Sep 10, 2024
1 parent 086e5a0 commit acee9ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions custom_components/toshiba_ac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Toshiba AC integration."""

from __future__ import annotations

import logging
Expand All @@ -15,6 +16,27 @@
_LOGGER = logging.getLogger(__name__)


async def sas_token_updated_for_entry(
hass: HomeAssistant, entry: ConfigEntry, new_sas_token: str
):
"""Update SAS token."""
_LOGGER.info("SAS token updated")

new_data = {**entry.data, "sas_token": new_sas_token}
hass.config_entries.async_update_entry(entry, data=new_data)


def add_sas_token_updated_callback_for_entry(
hass: HomeAssistant, entry: ConfigEntry, device_manager: ToshibaAcDeviceManager
):
"""Set up SAS token update callback."""

async def wrapper_callback(new_sas_token: str):
await sas_token_updated_for_entry(hass, entry, new_sas_token)

device_manager.on_sas_token_updated_callback.add(wrapper_callback)


async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the Hello World component."""
# Ensure our name space for storing objects is a known type. A dict is
Expand Down Expand Up @@ -55,6 +77,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
_LOGGER.warning("Connection failed on second try, aborting!")
return False

add_sas_token_updated_callback_for_entry(hass, entry, device_manager)

hass.data[DOMAIN][entry.entry_id] = device_manager

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/toshiba_ac/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"homekit": {},
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/h4de5/home-assistant-toshiba_ac/issues",
"requirements": ["toshiba-ac==0.3.7","janus==1.0.0"],
"requirements": ["toshiba-ac==0.3.9","janus==1.0.0"],
"ssdp": [],
"version": "2024.8.0",
"zeroconf": []
Expand Down

0 comments on commit acee9ec

Please sign in to comment.