Skip to content

Commit

Permalink
fix unload of datahandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Sdahl1234 committed Nov 5, 2024
1 parent 619abb8 commit d5c9003
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions custom_components/adano/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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(" ", "_")),
)
Expand Down
4 changes: 4 additions & 0 deletions custom_components/adano/adano.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down
1 change: 1 addition & 0 deletions custom_components/adano/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SERIAL_NO = "serial_no"
DOMAIN = "adano"
ROBOTS = "robots"
DATAHANDLER = "DATAHANDLER"
DH = "dh"

ADANO_STANDBY = "Standby"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/adano/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"integration_type": "device",
"iot_class": "cloud_push",
"config_flow": true,
"version": "1.0.15"
"version": "1.0.16"
}

0 comments on commit d5c9003

Please sign in to comment.