From 005ffa0d3b4485f7bbbc9f5ca0daf42fb812a2c2 Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Thu, 2 Jun 2022 22:50:24 -0400 Subject: [PATCH] Fix device ID handling in device_trigger --- custom_components/hubitat/device_trigger.py | 8 +++----- custom_components/hubitat/util.py | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/custom_components/hubitat/device_trigger.py b/custom_components/hubitat/device_trigger.py index 9702959..1592310 100644 --- a/custom_components/hubitat/device_trigger.py +++ b/custom_components/hubitat/device_trigger.py @@ -16,6 +16,8 @@ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, cast import voluptuous as vol +from custom_components.hubitat.util import get_hubitat_device_id + from homeassistant.components.automation import ( AutomationActionType, AutomationTriggerInfo, @@ -201,11 +203,7 @@ def get_hubitat_device( if device is None: return None, None - hubitat_id = None - for identifier in device.identifiers: - if identifier[0] == DOMAIN: - hubitat_id = identifier[1] - break + hubitat_id = get_hubitat_device_id(device) if hubitat_id is None: _LOGGER.debug("Couldn't find Hubitat ID for device %s", device_id) diff --git a/custom_components/hubitat/util.py b/custom_components/hubitat/util.py index 17594e1..4a8b23e 100644 --- a/custom_components/hubitat/util.py +++ b/custom_components/hubitat/util.py @@ -36,9 +36,7 @@ def get_hub_device_id(hub: HasToken, device: Union[str, Device]) -> str: def get_hubitat_device_id(device: DeviceEntry) -> Optional[str]: - for ids in device.identifiers: - id_set = ids[0] - + for id_set in device.identifiers: if id_set[0] == DOMAIN: # The second identifier is hub_id:device_id if ":" in id_set[1]: