Skip to content

Commit

Permalink
Fix write state and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Dec 20, 2021
1 parent d3685c8 commit e5df65d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
12 changes: 7 additions & 5 deletions custom_components/sector/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
STATE_ALARM_ARMED_HOME,
STATE_ALARM_DISARMED,
)
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,7 +88,7 @@ async def async_alarm_arm_home(self, code=None) -> None:
if code:
await self._hub.triggeralarm(command, code=code)
self._attr_state = STATE_ALARM_ARMED_HOME
await self.async_write_ha_state()
self.async_write_ha_state()

async def async_alarm_disarm(self, code=None) -> None:
"""Arm alarm off."""
Expand All @@ -98,7 +98,7 @@ async def async_alarm_disarm(self, code=None) -> None:
if code:
await self._hub.triggeralarm(command, code=code)
self._attr_state = STATE_ALARM_DISARMED
await self.async_write_ha_state()
self.async_write_ha_state()

async def async_alarm_arm_away(self, code=None) -> None:
"""Arm alarm away."""
Expand All @@ -108,10 +108,12 @@ async def async_alarm_arm_away(self, code=None) -> None:
if code:
await self._hub.triggeralarm(command, code=code)
self._attr_state = STATE_ALARM_ARMED_AWAY
await self.async_write_ha_state()
self.async_write_ha_state()

def update(self) -> None:
@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()
10 changes: 6 additions & 4 deletions custom_components/sector/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from homeassistant.components.lock import LockEntity, LockEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_CODE, STATE_LOCKED
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 @@ -111,7 +111,7 @@ async def async_unlock(self, **kwargs) -> None:
if code:
await self._hub.triggerlock(self.entity_description.key, code, command)
self._attr_is_locked = False
await self.async_write_ha_state()
self.async_write_ha_state()

async def async_lock(self, **kwargs) -> None:
"""Lock lock."""
Expand All @@ -120,10 +120,12 @@ async def async_lock(self, **kwargs) -> None:
if code:
await self._hub.triggerlock(self.entity_description.key, code, command)
self._attr_is_locked = True
await self.async_write_ha_state()
self.async_write_ha_state()

def update(self) -> None:
@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] == "lock"
)
self.async_write_ha_state()
2 changes: 1 addition & 1 deletion custom_components/sector/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"documentation": "https://github.com/gjohansson-ST/sector/blob/master/readme.md",
"issue_tracker": "https://github.com/gjohansson-ST/sector/issues",
"codeowners": ["@gjohansson-ST"],
"version": "v0.3.3",
"version": "v0.3.4",
"config_flow": true,
"iot_class": "cloud_polling"
}
6 changes: 4 additions & 2 deletions 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 @@ -89,6 +89,8 @@ def extra_state_attributes(self) -> dict:
"""Extra states for sensor."""
return {"Serial No": self.entity_description.key}

def update(self) -> None:
@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()
10 changes: 6 additions & 4 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 @@ -88,16 +88,18 @@ async def async_turn_on(self, **kwargs) -> None:
"""Turn the switch on."""
await self._hub.triggerswitch(self._id, "On")
self._attr_is_on = True
await self.async_write_ha_state
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn the switch off."""
await self._hub.triggerswitch(self._id, "Off")
self._attr_is_on = False
await self.async_write_ha_state
self.async_write_ha_state()

def update(self) -> None:
@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 e5df65d

Please sign in to comment.