diff --git a/custom_components/adano/__init__.py b/custom_components/adano/__init__.py index a9fd8bc..2cd7d30 100644 --- a/custom_components/adano/__init__.py +++ b/custom_components/adano/__init__.py @@ -12,7 +12,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from .adano import AdanoRoboticmower -from .const import DH, DOMAIN, ROBOTS +from .const import DATAHANDLER, DH, DOMAIN, ROBOTS PLATFORMS = [ Platform.BINARY_SENSOR, @@ -61,6 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): ) hass.data[DOMAIN][entry.entry_id][ROBOTS] = robots + hass.data[DOMAIN][entry.entry_id][DATAHANDLER] = data_handler await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) @@ -78,6 +79,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: + dh: AdanoRoboticmower + dh = hass.data[DOMAIN][entry.entry_id][DATAHANDLER] + dh.unload() hass.data[DOMAIN].pop(entry.entry_id) return unload_ok @@ -114,7 +118,7 @@ def __init__( self.data_handler = data_handler self.devicesn = devicesn self.data_handler.get_device(devicesn).dataupdated = self.dataupdated - self.filepath = os.path.join( + self.filepath = os.path.join( # noqa: PTH118 self.hass.config.config_dir, "Schedule-{}.json".format(self.devicesn.replace(" ", "_")), ) diff --git a/custom_components/adano/adano.py b/custom_components/adano/adano.py index 461cd3a..27c805e 100644 --- a/custom_components/adano/adano.py +++ b/custom_components/adano/adano.py @@ -143,6 +143,7 @@ def GetDay(self, daynumber: int) -> AdanoScheduleDay: for day in self.days: if day.day == daynumber: return day + return None def UpdateFromMqtt(self, data, daynumber: int) -> None: """From mqtt.""" @@ -198,6 +199,7 @@ def get_device(self, devicesn) -> AdanoDevice: for device in self.robotList: if device.devicesn == devicesn: return device + return None def update(self): """Force HA to update sensors.""" @@ -613,6 +615,8 @@ def unload(self): self.refresh_token_timeout.cancel() if self.refresh_token_interval: self.refresh_token_interval.cancel() + if self.mqtt_client.is_connected(): + self.mqtt_client.disconnect() def start_mowing(self, devicesn): """Start Mowing.""" diff --git a/custom_components/adano/const.py b/custom_components/adano/const.py index ea0c4a6..32b7fa3 100644 --- a/custom_components/adano/const.py +++ b/custom_components/adano/const.py @@ -3,6 +3,7 @@ SERIAL_NO = "serial_no" DOMAIN = "adano" ROBOTS = "robots" +DATAHANDLER = "DATAHANDLER" DH = "dh" ADANO_STANDBY = "Standby" diff --git a/custom_components/adano/manifest.json b/custom_components/adano/manifest.json index 2e6e831..d391ba8 100644 --- a/custom_components/adano/manifest.json +++ b/custom_components/adano/manifest.json @@ -8,5 +8,5 @@ "integration_type": "device", "iot_class": "cloud_push", "config_flow": true, - "version": "1.0.15" + "version": "1.0.16" } \ No newline at end of file