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
pull/91806/head
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[DOMAIN][entry.entry_id] = hub
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:
raise ConfigEntryNotReady(
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.
"""
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:
return False
_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.
"""
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:
return False
_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._protocol: str = entry.data[CONF_PROTOCOL]
self.sia_accounts: list[SIAAccount] | None = None
self.sia_client: SIAClient = None
self.sia_client: SIAClient | None = None
@callback
def async_setup_hub(self) -> None:
@ -70,7 +70,8 @@ class SIAHub:
async def async_shutdown(self, _: Event | None = None) -> None:
"""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:
"""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:
self.sia_client.accounts = self.sia_accounts
return
self.sia_client = SIAClient(
host="",
port=self._port,
accounts=self.sia_accounts,
function=self.async_create_and_fire_event,
protocol=CommunicationsProtocol(self._protocol),
# the new client class method creates a subclass based on protocol, hence the type ignore
self.sia_client = (
SIAClient( # pylint: disable=abstract-class-instantiated # type: ignore
host="",
port=self._port,
accounts=self.sia_accounts,
function=self.async_create_and_fire_event,
protocol=CommunicationsProtocol(self._protocol),
)
)
def _load_options(self) -> None:

View File

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/sia",
"iot_class": "local_push",
"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.
"""
_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
relevant_event = self.update_state(sia_event)

View File

@ -1,10 +1,11 @@
"""Helper functions for the SIA integration."""
from __future__ import annotations
from datetime import timedelta
from datetime import datetime, timedelta
from typing import Any
from pysiaalarm import SIAEvent
from pysiaalarm.utils import MessageTypes
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]:
"""Create the attributes dict from a SIAEvent."""
timestamp = event.timestamp if event.timestamp else utcnow()
return {
ATTR_ZONE: event.ri,
ATTR_CODE: event.code,
ATTR_MESSAGE: event.message,
ATTR_ID: event.id,
ATTR_TIMESTAMP: event.timestamp.isoformat()
if event.timestamp
else utcnow().isoformat(),
ATTR_TIMESTAMP: timestamp.isoformat()
if isinstance(timestamp, datetime)
else timestamp,
}
def get_event_data_from_sia_event(event: SIAEvent) -> dict[str, Any]:
"""Create a dict from the SIA Event for the HA Event."""
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,
"line": event.line,
"account": event.account,
@ -77,8 +81,8 @@ def get_event_data_from_sia_event(event: SIAEvent) -> dict[str, Any]:
"message": event.message,
"x_data": event.x_data,
"timestamp": event.timestamp.isoformat()
if event.timestamp
else utcnow().isoformat(),
if isinstance(event.timestamp, datetime)
else event.timestamp,
"event_qualifier": event.event_qualifier,
"event_type": event.event_type,
"partition": event.partition,

View File

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

View File

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