From 3a9a9c9e7f8f291be26c1ed0f298dbef96700a79 Mon Sep 17 00:00:00 2001 From: cyr-ius Date: Fri, 27 Oct 2023 15:04:31 +0200 Subject: [PATCH] Add detection if a lock switch exists --- custom_components/heatzy/const.py | 1 + custom_components/heatzy/switch.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/custom_components/heatzy/const.py b/custom_components/heatzy/const.py index 9f2af26..a8f9b1c 100644 --- a/custom_components/heatzy/const.py +++ b/custom_components/heatzy/const.py @@ -1,4 +1,5 @@ """Constants for the Heatzy component.""" +ATTR_LOCK_SWITCH = "lock_switch" API_TIMEOUT = 30 CFT_TEMP_H = "cft_tempH" CFT_TEMP_L = "cft_tempL" diff --git a/custom_components/heatzy/switch.py b/custom_components/heatzy/switch.py index 52f0b29..1e78b77 100644 --- a/custom_components/heatzy/switch.py +++ b/custom_components/heatzy/switch.py @@ -4,6 +4,7 @@ import logging from heatzypy.exception import HeatzyException + from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -12,7 +13,15 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import HeatzyDataUpdateCoordinator -from .const import CONF_ATTR, CONF_ATTRS, CONF_LOCK, DOMAIN +from .const import ( + ATTR_LOCK_SWITCH, + CONF_ATTR, + CONF_ATTRS, + CONF_LOCK, + CONF_PRODUCT_KEY, + DOMAIN, + PILOTE_V2, +) _LOGGER = logging.getLogger(__name__) @@ -22,10 +31,10 @@ async def async_setup_entry( ) -> None: """Set the sensor platform.""" coordinator = hass.data[DOMAIN][entry.entry_id] - entities = [ - LockSwitchEntity(coordinator, unique_id) - for unique_id in coordinator.data.keys() - ] + entities: list[LockSwitchEntity] = [] + for unique_id, device in coordinator.data.items(): + if device.get(CONF_ATTR, {}).get(ATTR_LOCK_SWITCH): + entities.append(LockSwitchEntity(coordinator, unique_id)) async_add_entities(entities)