Improve totalconnect
generic typing (#84650)
This commit is contained in:
parent
d441fb2ec5
commit
572af57ffe
2 changed files with 20 additions and 9 deletions
|
@ -78,10 +78,12 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
client.locations[location_id].auto_bypass_low_battery = bypass
|
client.locations[location_id].auto_bypass_low_battery = bypass
|
||||||
|
|
||||||
|
|
||||||
class TotalConnectDataUpdateCoordinator(DataUpdateCoordinator):
|
class TotalConnectDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||||
"""Class to fetch data from TotalConnect."""
|
"""Class to fetch data from TotalConnect."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, client):
|
config_entry: ConfigEntry
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant, client: TotalConnectClient) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.client = client
|
self.client = client
|
||||||
|
@ -89,11 +91,11 @@ class TotalConnectDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
hass, logger=_LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL
|
hass, logger=_LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _async_update_data(self):
|
async def _async_update_data(self) -> None:
|
||||||
"""Update data."""
|
"""Update data."""
|
||||||
await self.hass.async_add_executor_job(self.sync_update_data)
|
await self.hass.async_add_executor_job(self.sync_update_data)
|
||||||
|
|
||||||
def sync_update_data(self):
|
def sync_update_data(self) -> None:
|
||||||
"""Fetch synchronous data from TotalConnect."""
|
"""Fetch synchronous data from TotalConnect."""
|
||||||
try:
|
try:
|
||||||
for location_id in self.client.locations:
|
for location_id in self.client.locations:
|
||||||
|
|
|
@ -24,6 +24,7 @@ from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from . import TotalConnectDataUpdateCoordinator
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
SERVICE_ALARM_ARM_AWAY_INSTANT = "arm_away_instant"
|
SERVICE_ALARM_ARM_AWAY_INSTANT = "arm_away_instant"
|
||||||
|
@ -36,7 +37,7 @@ async def async_setup_entry(
|
||||||
"""Set up TotalConnect alarm panels based on a config entry."""
|
"""Set up TotalConnect alarm panels based on a config entry."""
|
||||||
alarms = []
|
alarms = []
|
||||||
|
|
||||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: TotalConnectDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
for location_id, location in coordinator.client.locations.items():
|
for location_id, location in coordinator.client.locations.items():
|
||||||
location_name = location.location_name
|
location_name = location.location_name
|
||||||
|
@ -68,7 +69,9 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TotalConnectAlarm(CoordinatorEntity, alarm.AlarmControlPanelEntity):
|
class TotalConnectAlarm(
|
||||||
|
CoordinatorEntity[TotalConnectDataUpdateCoordinator], alarm.AlarmControlPanelEntity
|
||||||
|
):
|
||||||
"""Represent an TotalConnect status."""
|
"""Represent an TotalConnect status."""
|
||||||
|
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
|
@ -77,7 +80,13 @@ class TotalConnectAlarm(CoordinatorEntity, alarm.AlarmControlPanelEntity):
|
||||||
| AlarmControlPanelEntityFeature.ARM_NIGHT
|
| AlarmControlPanelEntityFeature.ARM_NIGHT
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, coordinator, name, location_id, partition_id):
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: TotalConnectDataUpdateCoordinator,
|
||||||
|
name,
|
||||||
|
location_id,
|
||||||
|
partition_id,
|
||||||
|
):
|
||||||
"""Initialize the TotalConnect status."""
|
"""Initialize the TotalConnect status."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._location_id = location_id
|
self._location_id = location_id
|
||||||
|
@ -85,7 +94,7 @@ class TotalConnectAlarm(CoordinatorEntity, alarm.AlarmControlPanelEntity):
|
||||||
self._partition_id = partition_id
|
self._partition_id = partition_id
|
||||||
self._partition = self._location.partitions[partition_id]
|
self._partition = self._location.partitions[partition_id]
|
||||||
self._device = self._location.devices[self._location.security_device_id]
|
self._device = self._location.devices[self._location.security_device_id]
|
||||||
self._state = None
|
self._state: str | None = None
|
||||||
self._attr_extra_state_attributes = {}
|
self._attr_extra_state_attributes = {}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -122,7 +131,7 @@ class TotalConnectAlarm(CoordinatorEntity, alarm.AlarmControlPanelEntity):
|
||||||
"triggered_zone": None,
|
"triggered_zone": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
state = None
|
state: str | None = None
|
||||||
if self._partition.arming_state.is_disarmed():
|
if self._partition.arming_state.is_disarmed():
|
||||||
state = STATE_ALARM_DISARMED
|
state = STATE_ALARM_DISARMED
|
||||||
elif self._partition.arming_state.is_armed_night():
|
elif self._partition.arming_state.is_armed_night():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue