Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #20 from eavanvalkenburg/beta
Browse files Browse the repository at this point in the history
New package
  • Loading branch information
eavanvalkenburg authored Jul 16, 2020
2 parents cec5d3e + 5c41cc4 commit f8fecbd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
37 changes: 20 additions & 17 deletions custom_components/sia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""

await hass.data[DOMAIN][entry.entry_id].sia_client.stop()
hass.data[DOMAIN][entry.entry_id].shutdown_remove_listener()
unload_ok = all(
Expand Down Expand Up @@ -131,13 +130,7 @@ def __init__(
self.sia_client = SIAClient(
"", self._port, self.sia_accounts, self.update_states
)

for zone in self._zones:
ping = self._get_ping_interval(zone[CONF_ACCOUNT])
for sensor in zone[CONF_SENSORS]:
self._create_sensor(
self._port, zone[CONF_ACCOUNT], zone[CONF_ZONE], sensor, ping
)
self._create_sensors()

async def async_setup_hub(self):
"""Add a device to the device_registry, register shutdown listener, load reactions."""
Expand All @@ -158,6 +151,15 @@ async def async_shutdown(self, _: Event):
"""Shutdown the SIA server."""
await self.sia_client.stop()

def _create_sensors(self):
"""Create all the sensors."""
for zone in self._zones:
ping = self._get_ping_interval(zone[CONF_ACCOUNT])
for entity_type in zone[CONF_SENSORS]:
self._create_sensor(
self._port, zone[CONF_ACCOUNT], zone[CONF_ZONE], entity_type, ping
)

def _create_sensor(
self, port: int, account: str, zone: int, entity_type: str, ping: int
):
Expand All @@ -166,11 +168,12 @@ def _create_sensor(
account, zone, entity_type
)
if entity_type == DEVICE_CLASS_ALARM:
new_entity = SIAAlarmControlPanel(
self.states[entity_id] = SIAAlarmControlPanel(
entity_id, entity_name, port, account, zone, ping, self._hass
)
elif entity_type in (DEVICE_CLASS_MOISTURE, DEVICE_CLASS_SMOKE):
new_entity = SIABinarySensor(
return
if entity_type in (DEVICE_CLASS_MOISTURE, DEVICE_CLASS_SMOKE):
self.states[entity_id] = SIABinarySensor(
entity_id,
entity_name,
entity_type,
Expand All @@ -180,8 +183,9 @@ def _create_sensor(
ping,
self._hass,
)
elif entity_type == DEVICE_CLASS_TIMESTAMP:
new_entity = SIASensor(
return
if entity_type == DEVICE_CLASS_TIMESTAMP:
self.states[entity_id] = SIASensor(
entity_id,
entity_name,
entity_type,
Expand All @@ -191,7 +195,6 @@ def _create_sensor(
ping,
self._hass,
)
self.states[entity_id] = new_entity

def _get_entity_id_and_name(
self, account: str, zone: int = 0, entity_type: str = None
Expand Down Expand Up @@ -233,13 +236,13 @@ async def update_states(self, event: SIAEvent):
# find the reactions for that code (if any)
reaction = self._reactions.get(event.code)
if not reaction:
_LOGGER.warning(
"Unhandled event code: %s, Message: %s, Full event: %s",
_LOGGER.info(
"Unhandled event code, will be set as attribute in the heartbeat. Code is: %s, Message: %s, Full event: %s",
event.code,
event.message,
event.sia_string,
)
return
reaction = {"type": DEVICE_CLASS_TIMESTAMP, "attr": LAST_MESSAGE}
attr = reaction.get("attr")
new_state = reaction.get("new_state")
new_state_eval = reaction.get("new_state_eval")
Expand Down
1 change: 0 additions & 1 deletion custom_components/sia/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def __init__(
hass: HomeAssistant,
):
"""Create SIABinarySensor object."""

self.entity_id = BINARY_SENSOR_FORMAT.format(entity_id)
self._unique_id = entity_id
self._name = name
Expand Down
10 changes: 7 additions & 3 deletions custom_components/sia/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"name": "SIA Alarm Systems",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/sia",
"requirements": ["pysiaalarm==2.0.3"],
"codeowners": ["@eavanvalkenburg"]
}
"requirements": [
"pysiaalarm==2.0.5"
],
"codeowners": [
"@eavanvalkenburg"
]
}

0 comments on commit f8fecbd

Please sign in to comment.