Skip to content

Commit

Permalink
Patch Update
Browse files Browse the repository at this point in the history
  • Loading branch information
lunDreame authored Jan 1, 2025
1 parent 4c42a13 commit 93b5231
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion custom_components/kocom_wallpad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from homeassistant.const import Platform
from homeassistant.const import Platform, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry

Expand Down Expand Up @@ -32,6 +32,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await gateway.async_start()

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
#entry.async_on_unload(
# hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, gateway.async_close)
#)

return True

Expand Down
9 changes: 5 additions & 4 deletions custom_components/kocom_wallpad/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class KocomEntity(RestoreEntity):
"""Base class for Kocom Wallpad entities."""

_attr_has_entity_name = True
_attr_should_poll = True
_attr_should_poll = False

def __init__(
self,
Expand Down Expand Up @@ -85,10 +85,11 @@ def available(self) -> bool:
return self.gateway.connection.is_connected()

@callback
def async_handle_device_update(self, device: Device) -> None:
def async_handle_device_update(self, packet: KocomPacket) -> None:
"""Handle device update."""
if self.device.state != device.state:
self.device.state = device.state
if self.packet._device.state != packet._device.state:
self.packet = packet
self.device = packet._device
self.async_write_ha_state()

async def async_added_to_hass(self) -> None:
Expand Down
8 changes: 6 additions & 2 deletions custom_components/kocom_wallpad/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from homeassistant.const import Platform, CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, Event
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers import entity_registry as er, restore_state
Expand Down Expand Up @@ -60,6 +60,10 @@ async def async_start(self) -> None:
await self.client.start()
self.client.add_device_callback(self._handle_device_update)

async def async_close(self, event: Event) -> None:
"""Close the gateway."""
await self.async_disconnect()

def get_entities(self, platform: Platform) -> list[KocomPacket]:
"""Get the entities for the platform."""
return list(self.entities.get(platform, {}).values())
Expand Down Expand Up @@ -105,7 +109,7 @@ async def _handle_device_update(self, packet: KocomPacket) -> None:
async_dispatcher_send(self.hass, add_signal, packet)

device_update_signal = f"{DOMAIN}_{self.host}_{dev_id}"
async_dispatcher_send(self.hass, device_update_signal, device)
async_dispatcher_send(self.hass, device_update_signal, packet)

def parse_platform(self, packet: KocomPacket) -> Platform | None:
"""Parse the platform from the packet."""
Expand Down

0 comments on commit 93b5231

Please sign in to comment.