Skip to content

Commit

Permalink
Fixed bugs in device triggers.
Browse files Browse the repository at this point in the history
Reworked device identification for triggers.
Fixes #26
  • Loading branch information
tschamm committed May 3, 2021
1 parent d15540d commit 74e3bbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
42 changes: 16 additions & 26 deletions custom_components/bosch_shc/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List, Tuple

import voluptuous as vol
from boschshcpy import SHCDevice
from boschshcpy import SHCDevice, SHCSession
from homeassistant.components.automation import AutomationActionType
from homeassistant.components.device_automation import TRIGGER_BASE_SCHEMA
from homeassistant.components.device_automation.exceptions import (
Expand All @@ -26,6 +26,7 @@
ATTR_EVENT_SUBTYPE,
ATTR_EVENT_TYPE,
CONF_SUBTYPE,
DATA_SESSION,
DOMAIN,
EVENT_BOSCH_SHC,
INPUTS_EVENTS_SUBTYPES,
Expand All @@ -44,35 +45,24 @@ async def get_device_from_id(hass, device_id) -> Tuple[SHCDevice, str]:
"""Get the device for the given device id."""
dev_registry = await dr.async_get_registry(hass)
for config_entry in hass.data[DOMAIN]:
session = hass.data[DOMAIN][config_entry]

for switch_device in session.device_helper.universal_switches:
device = dev_registry.async_get_device(
identifiers={(DOMAIN, switch_device.id)}, connections=set()
)
if device.id == device_id:
return switch_device, "WRC2"

for motion_device in session.device_helper.motion_detectors:
device = dev_registry.async_get_device(
identifiers={(DOMAIN, motion_device.id)}, connections=set()
)
if device.id == device_id:
return motion_device, "MD"
session: SHCSession = hass.data[DOMAIN][config_entry][DATA_SESSION]

for smoke_device in session.device_helper.smoke_detectors:
for shc_device in session.devices:
device = dev_registry.async_get_device(
identifiers={(DOMAIN, smoke_device.id)}, connections=set()
)
if device.id == device_id:
return smoke_device, "SD"

for smoke_detection_system in session.device_helper.smoke_detection_system:
identifiers={(DOMAIN, shc_device.id)}, connections=set()
)
if device is None or device.id != device_id:
continue
return shc_device, shc_device.device_model

ids = session.intrusion_system
if ids:
device = dev_registry.async_get_device(
identifiers={(DOMAIN, smoke_detection_system.id)}, connections=set()
identifiers={(DOMAIN, ids.id)}, connections=set()
)
if device.id == device_id:
return smoke_detection_system, "SMOKE_DETECTION_SYSTEM"
return ids, "IDS"

device = dev_registry.async_get_device(
identifiers={(DOMAIN, session.information.name)}, connections=set()
Expand All @@ -84,7 +74,7 @@ async def get_device_from_id(hass, device_id) -> Tuple[SHCDevice, str]:


async def async_get_triggers(hass: HomeAssistant, device_id: str) -> List[dict]:
"""List device triggers for Shelly devices."""
"""List device triggers for SHC devices."""
triggers = []

device, dev_type = await get_device_from_id(hass, device_id)
Expand Down Expand Up @@ -120,7 +110,7 @@ async def async_get_triggers(hass: HomeAssistant, device_id: str) -> List[dict]:
}
)

if dev_type in ("SD", "SDS"):
if dev_type in ("SD", "SMOKE_DETECTION_SYSTEM"):
for subtype in ALARM_EVENTS_SUBTYPES:
triggers.append(
{
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bosch_shc/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://github.com/tschamm/boschshc-hass/blob/master/README.md",
"requirements": ["boschshcpy==0.2.15"],
"version": "0.4.0",
"version": "0.4.1",
"zeroconf": [
{"type": "_http._tcp.local.", "name": "bosch shc*"}
],
Expand Down

0 comments on commit 74e3bbe

Please sign in to comment.