Update pysiaalarm to 3.1.0 (#91500)

* updated sia requirements

* updates because of changes in package

* linting and other small fixes

* linting and other small fixes

* small release on package that fixes issue with autospec
This commit is contained in:
Eduard van Valkenburg 2023-04-21 10:51:49 +02:00 committed by GitHub
parent faf78fc6b1
commit 09517668fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 22 deletions

View file

@ -16,7 +16,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = hub hass.data[DOMAIN][entry.entry_id] = hub
try: try:
await hub.sia_client.start(reuse_port=True) if hub.sia_client:
await hub.sia_client.start(reuse_port=True)
except OSError as exc: except OSError as exc:
raise ConfigEntryNotReady( raise ConfigEntryNotReady(
f"SIA Server at port {entry.data[CONF_PORT]} could not start." f"SIA Server at port {entry.data[CONF_PORT]} could not start."

View file

@ -121,7 +121,9 @@ class SIAAlarmControlPanel(SIABaseEntity, AlarmControlPanelEntity):
Return True if the event was relevant for this entity. Return True if the event was relevant for this entity.
""" """
new_state = self.entity_description.code_consequences.get(sia_event.code) new_state = None
if sia_event.code:
new_state = self.entity_description.code_consequences[sia_event.code]
if new_state is None: if new_state is None:
return False return False
_LOGGER.debug("New state will be %s", new_state) _LOGGER.debug("New state will be %s", new_state)

View file

@ -130,7 +130,9 @@ class SIABinarySensor(SIABaseEntity, BinarySensorEntity):
Return True if the event was relevant for this entity. Return True if the event was relevant for this entity.
""" """
new_state = self.entity_description.code_consequences.get(sia_event.code) new_state = None
if sia_event.code:
new_state = self.entity_description.code_consequences[sia_event.code]
if new_state is None: if new_state is None:
return False return False
_LOGGER.debug("New state will be %s", new_state) _LOGGER.debug("New state will be %s", new_state)

View file

@ -47,7 +47,7 @@ class SIAHub:
self._accounts: list[dict[str, Any]] = deepcopy(entry.data[CONF_ACCOUNTS]) self._accounts: list[dict[str, Any]] = deepcopy(entry.data[CONF_ACCOUNTS])
self._protocol: str = entry.data[CONF_PROTOCOL] self._protocol: str = entry.data[CONF_PROTOCOL]
self.sia_accounts: list[SIAAccount] | None = None self.sia_accounts: list[SIAAccount] | None = None
self.sia_client: SIAClient = None self.sia_client: SIAClient | None = None
@callback @callback
def async_setup_hub(self) -> None: def async_setup_hub(self) -> None:
@ -70,7 +70,8 @@ class SIAHub:
async def async_shutdown(self, _: Event | None = None) -> None: async def async_shutdown(self, _: Event | None = None) -> None:
"""Shutdown the SIA server.""" """Shutdown the SIA server."""
await self.sia_client.stop() if self.sia_client:
await self.sia_client.stop()
async def async_create_and_fire_event(self, event: SIAEvent) -> None: async def async_create_and_fire_event(self, event: SIAEvent) -> None:
"""Create a event on HA dispatcher and then on HA's bus, with the data from the SIAEvent. """Create a event on HA dispatcher and then on HA's bus, with the data from the SIAEvent.
@ -108,12 +109,15 @@ class SIAHub:
if self.sia_client is not None: if self.sia_client is not None:
self.sia_client.accounts = self.sia_accounts self.sia_client.accounts = self.sia_accounts
return return
self.sia_client = SIAClient( # the new client class method creates a subclass based on protocol, hence the type ignore
host="", self.sia_client = (
port=self._port, SIAClient( # pylint: disable=abstract-class-instantiated # type: ignore
accounts=self.sia_accounts, host="",
function=self.async_create_and_fire_event, port=self._port,
protocol=CommunicationsProtocol(self._protocol), accounts=self.sia_accounts,
function=self.async_create_and_fire_event,
protocol=CommunicationsProtocol(self._protocol),
)
) )
def _load_options(self) -> None: def _load_options(self) -> None:

View file

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/sia", "documentation": "https://www.home-assistant.io/integrations/sia",
"iot_class": "local_push", "iot_class": "local_push",
"loggers": ["pysiaalarm"], "loggers": ["pysiaalarm"],
"requirements": ["pysiaalarm==3.0.2"] "requirements": ["pysiaalarm==3.1.1"]
} }

View file

@ -126,7 +126,7 @@ class SIABaseEntity(RestoreEntity):
then update the availability and schedule the next unavailability check. then update the availability and schedule the next unavailability check.
""" """
_LOGGER.debug("Received event: %s", sia_event) _LOGGER.debug("Received event: %s", sia_event)
if int(sia_event.ri) not in (self.zone, SIA_HUB_ZONE): if (int(sia_event.ri) if sia_event.ri else 0) not in (self.zone, SIA_HUB_ZONE):
return return
relevant_event = self.update_state(sia_event) relevant_event = self.update_state(sia_event)

View file

@ -1,10 +1,11 @@
"""Helper functions for the SIA integration.""" """Helper functions for the SIA integration."""
from __future__ import annotations from __future__ import annotations
from datetime import timedelta from datetime import datetime, timedelta
from typing import Any from typing import Any
from pysiaalarm import SIAEvent from pysiaalarm import SIAEvent
from pysiaalarm.utils import MessageTypes
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
@ -50,21 +51,24 @@ def get_unavailability_interval(ping: int) -> float:
def get_attr_from_sia_event(event: SIAEvent) -> dict[str, Any]: def get_attr_from_sia_event(event: SIAEvent) -> dict[str, Any]:
"""Create the attributes dict from a SIAEvent.""" """Create the attributes dict from a SIAEvent."""
timestamp = event.timestamp if event.timestamp else utcnow()
return { return {
ATTR_ZONE: event.ri, ATTR_ZONE: event.ri,
ATTR_CODE: event.code, ATTR_CODE: event.code,
ATTR_MESSAGE: event.message, ATTR_MESSAGE: event.message,
ATTR_ID: event.id, ATTR_ID: event.id,
ATTR_TIMESTAMP: event.timestamp.isoformat() ATTR_TIMESTAMP: timestamp.isoformat()
if event.timestamp if isinstance(timestamp, datetime)
else utcnow().isoformat(), else timestamp,
} }
def get_event_data_from_sia_event(event: SIAEvent) -> dict[str, Any]: def get_event_data_from_sia_event(event: SIAEvent) -> dict[str, Any]:
"""Create a dict from the SIA Event for the HA Event.""" """Create a dict from the SIA Event for the HA Event."""
return { return {
"message_type": event.message_type.value, "message_type": event.message_type.value
if isinstance(event.message_type, MessageTypes)
else event.message_type,
"receiver": event.receiver, "receiver": event.receiver,
"line": event.line, "line": event.line,
"account": event.account, "account": event.account,
@ -77,8 +81,8 @@ def get_event_data_from_sia_event(event: SIAEvent) -> dict[str, Any]:
"message": event.message, "message": event.message,
"x_data": event.x_data, "x_data": event.x_data,
"timestamp": event.timestamp.isoformat() "timestamp": event.timestamp.isoformat()
if event.timestamp if isinstance(event.timestamp, datetime)
else utcnow().isoformat(), else event.timestamp,
"event_qualifier": event.event_qualifier, "event_qualifier": event.event_qualifier,
"event_type": event.event_type, "event_type": event.event_type,
"partition": event.partition, "partition": event.partition,

View file

@ -1954,7 +1954,7 @@ pysesame2==1.0.1
pysher==1.0.7 pysher==1.0.7
# homeassistant.components.sia # homeassistant.components.sia
pysiaalarm==3.0.2 pysiaalarm==3.1.1
# homeassistant.components.signal_messenger # homeassistant.components.signal_messenger
pysignalclirestapi==0.3.18 pysignalclirestapi==0.3.18

View file

@ -1425,7 +1425,7 @@ pyserial-asyncio==0.6
pyserial==3.5 pyserial==3.5
# homeassistant.components.sia # homeassistant.components.sia
pysiaalarm==3.0.2 pysiaalarm==3.1.1
# homeassistant.components.signal_messenger # homeassistant.components.signal_messenger
pysignalclirestapi==0.3.18 pysignalclirestapi==0.3.18