Skip to content

Commit

Permalink
Optim code
Browse files Browse the repository at this point in the history
  • Loading branch information
cyr-ius committed Jul 10, 2022
1 parent 16e1682 commit 6f4ce1d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions custom_components/heatzy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .const import DEBOUNCE_COOLDOWN, DOMAIN, PLATFORMS

_LOGGER = logging.getLogger(__name__)
UPDATE_INTERVAL = timedelta(minutes=5)
SCAN_INTERVAL = 60


async def async_setup_entry(hass, config_entry):
Expand Down Expand Up @@ -52,20 +52,22 @@ def __init__(
config_entry,
) -> None:
"""Class to manage fetching Heatzy data API."""
self.heatzy_client = HeatzyClient(
config_entry.data[CONF_USERNAME], config_entry.data[CONF_PASSWORD]
)
super().__init__(
hass,
_LOGGER,
name=DOMAIN,
update_interval=timedelta(seconds=60),
update_interval=timedelta(seconds=SCAN_INTERVAL),
request_refresh_debouncer=Debouncer(
hass, _LOGGER, cooldown=DEBOUNCE_COOLDOWN, immediate=False
),
)
self.heatzy_client = HeatzyClient(
config_entry.data[CONF_USERNAME], config_entry.data[CONF_PASSWORD]
)


async def _async_update_data(self) -> dict:
"""Update data."""
try:
devices = await self.heatzy_client.async_get_devices()
return {device["did"]: device for device in devices}
Expand Down
4 changes: 2 additions & 2 deletions custom_components/heatzy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ async def async_step_user(self, user_input=None):

api = HeatzyClient(user_input[CONF_USERNAME], user_input[CONF_PASSWORD])
await self.hass.async_add_executor_job(api.is_connected)

return self.async_create_entry(title=DOMAIN, data=user_input)
except HeatzyException:
errors["base"] = "cannot_connect"
else:
return self.async_create_entry(title=DOMAIN, data=user_input)

return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
Expand Down
2 changes: 1 addition & 1 deletion custom_components/heatzy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"requirements": ["heatzypy==2.0.4"],
"dependencies": [],
"codeowners": ["@cyr-ius"],
"version": "5.3.5",
"version": "5.4",
"iot_class": "cloud_polling"
}
6 changes: 3 additions & 3 deletions custom_components/heatzy/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class LockSwitchEntity(CoordinatorEntity, SwitchEntity):

entity_category = EntityCategory.CONFIG

def __init__(self, coordinator, _unique_id):
def __init__(self, coordinator, did):
"""Initialize switch."""
super().__init__(coordinator)
self._attr_unique_id = _unique_id
self._attr_unique_id = did
self._attr_name = "Lock switch {}".format(
coordinator.data[_unique_id]["dev_alias"]
coordinator.data[did]["dev_alias"]
)

@property
Expand Down

0 comments on commit 6f4ce1d

Please sign in to comment.