Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #176 from Thomas55555/add-lifecyle-hooks
Browse files Browse the repository at this point in the history
Add lifecyle hooks
  • Loading branch information
Thomas55555 authored Feb 17, 2022
2 parents 64dc7f1 + 4077e61 commit 7ce2a32
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion custom_components/husqvarna_automower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

import aioautomower

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME
from homeassistant.core import HomeAssistant
Expand Down
2 changes: 1 addition & 1 deletion custom_components/husqvarna_automower/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Config flow to add the integration via the UI."""
import logging

from aioautomower import GetAccessToken, GetMowerData, TokenError
from aiohttp.client_exceptions import ClientConnectorError, ClientResponseError
import voluptuous as vol

from aioautomower import GetAccessToken, GetMowerData, TokenError
from homeassistant import config_entries
from homeassistant.const import (
CONF_ACCESS_TOKEN,
Expand Down
16 changes: 12 additions & 4 deletions custom_components/husqvarna_automower/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def __init__(self, session, idx) -> None:
self.mower_name = mower_attributes["system"]["name"]
self.model = mower_attributes["system"]["model"]

self.session.register_cb(
lambda _: self.async_write_ha_state(), schedule_immediately=True
)

self._available = self.get_mower_attributes()["metadata"]["connected"]

self._event = None
Expand All @@ -36,6 +32,18 @@ def get_mower_attributes(self) -> dict:
"""Get the mower attributes of the current mower."""
return self.session.data["data"][self.idx]["attributes"]

async def async_added_to_hass(self) -> None:
"""Call when entity about to be added to Home Assistant."""
await super().async_added_to_hass()
self.session.register_data_callback(
lambda _: self.async_write_ha_state(), schedule_immediately=True
)

async def async_will_remove_from_hass(self) -> None:
"""Call when entity is being removed from Home Assistant."""
await super().async_will_remove_from_hass()
self.session.unregister_data_callback(lambda _: self.async_write_ha_state())

@property
def device_info(self) -> DeviceInfo:
"""Defines the DeviceInfo for the mower."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/husqvarna_automower/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@Thomas55555"
],
"requirements": [
"aioautomower==2022.2.0"
"aioautomower==2022.2.1"
],
"iot_class": "cloud_push",
"version": "0.0.0"
Expand Down
1 change: 0 additions & 1 deletion custom_components/husqvarna_automower/system_health.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provide info to system health."""
from aioautomower import TOKEN_URL

from homeassistant.components.system_health import (
SystemHealthRegistration,
async_check_can_reach_url,
Expand Down

0 comments on commit 7ce2a32

Please sign in to comment.