Skip to content

Commit

Permalink
Fix for non-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Dec 19, 2021
1 parent 1e19266 commit 7095e1c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
13 changes: 9 additions & 4 deletions custom_components/sector/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
SUPPORT_ALARM_ARM_HOME,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_ALARM_PENDING
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
Expand Down Expand Up @@ -49,8 +48,6 @@ def __init__(
self._hub = hub
super().__init__(coordinator)
self._code: str = code if code != "" else None
self._state: str = STATE_ALARM_PENDING
self._changed_by: str = ""
self._displayname: str = self._hub.alarm_displayname
self._isonline: str = self._hub.alarm_isonline
self._attr_name = f"Sector Alarmpanel {self._hub.alarm_id}"
Expand Down Expand Up @@ -104,3 +101,11 @@ async def async_alarm_arm_away(self, code=None) -> None:
if code:
await self._hub.triggeralarm(command, code=code)
await self.coordinator.async_refresh()

@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._isonline: str = self._hub.alarm_isonline
self._attr_changed_by = self._hub.alarm_changed_by
self._attr_state = self._hub.alarm_state
self.async_write_ha_state()
28 changes: 16 additions & 12 deletions custom_components/sector/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from homeassistant.components.lock import LockEntity, LockEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_CODE, STATE_LOCKED, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.const import ATTR_CODE, STATE_LOCKED
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
Expand Down Expand Up @@ -71,15 +71,16 @@ def __init__(
"""Initialize lock."""
self._hub = hub
super().__init__(coordinator)
self._serial = serial
self._attr_name = description.name
self._attr_unique_id: str = "sa_lock_" + str(description.key)
self._attr_code_format: str = f"^\\d{code_format}$"
self._attr_is_locked = bool(
self._hub.lock_state[description.key] == STATE_LOCKED
)
self._autolock = autolock
self._code = code
self.entity_description = description
self._code_format = code_format
self._state: str = STATE_UNKNOWN

@property
def device_info(self) -> DeviceInfo:
Expand All @@ -98,26 +99,29 @@ def extra_state_attributes(self) -> dict:
"""Additional states of lock."""
return {
"Autolock": self._autolock,
"Serial No": self._serial,
"Serial No": self.entity_description.key,
}

@property
def is_locked(self) -> bool:
"""Return if locked."""
return self._state == STATE_LOCKED

async def async_unlock(self, **kwargs) -> None:
"""Unlock lock."""
command = "unlock"
code = kwargs.get(ATTR_CODE, self._code)
if code:
await self._hub.triggerlock(self._serial, code, command)
await self._hub.triggerlock(self.entity_description.key, code, command)
await self.coordinator.async_refresh()

async def async_lock(self, **kwargs) -> None:
"""Lock lock."""
command = "lock"
code = kwargs.get(ATTR_CODE, self._code)
if code:
await self._hub.triggerlock(self._serial, code, command)
await self._hub.triggerlock(self.entity_description.key, code, command)
await self.coordinator.async_refresh()

@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_is_locked = bool(
self._hub.lock_state[self.entity_description.key] == STATE_LOCKED
)
self.async_write_ha_state()
8 changes: 7 additions & 1 deletion custom_components/sector/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
Expand Down Expand Up @@ -88,3 +88,9 @@ def device_info(self) -> DeviceInfo:
def extra_state_attributes(self) -> dict:
"""Extra states for sensor."""
return {"Serial No": self.entity_description.key}

@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_native_value = self._hub.temp_state[self.entity_description.key]
self.async_write_ha_state()
17 changes: 12 additions & 5 deletions custom_components/sector/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
SwitchEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
Expand Down Expand Up @@ -56,12 +56,11 @@ def __init__(
"""Initialize Switch."""
self._hub = hub
super().__init__(coordinator)
self._serial = description.key
self._attr_name = description.name
self._attr_unique_id: str = "sa_switch_" + str(description.key)
self.entity_description = description
self._attr_is_on = bool(self._hub.switch_state[self._serial] == "On")
self._id: str = self._hub.switch_id[self._serial]
self._attr_is_on = bool(self._hub.switch_state[description.key] == "On")
self._id: str = self._hub.switch_id[description.key]

@property
def device_info(self) -> DeviceInfo:
Expand All @@ -79,7 +78,7 @@ def device_info(self) -> DeviceInfo:
def extra_state_attributes(self) -> dict:
"""Additional states for switch."""
return {
"Serial No": self._serial,
"Serial No": self.entity_description.key,
"Id": self._id,
}

Expand All @@ -95,3 +94,11 @@ async def async_triggerswitch(self, command) -> None:
"""Trigger switch."""
await self._hub.triggerswitch(self._id, command)
await self.coordinator.async_refresh()

@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_is_on = bool(
self._hub.switch_state[self.entity_description.key] == "On"
)
self.async_write_ha_state()

0 comments on commit 7095e1c

Please sign in to comment.