Skip to content

Commit

Permalink
Add detection if a lock switch exists
Browse files Browse the repository at this point in the history
  • Loading branch information
cyr-ius committed Oct 27, 2023
1 parent 762c4f9 commit 3a9a9c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions custom_components/heatzy/const.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
19 changes: 14 additions & 5 deletions custom_components/heatzy/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)

Expand All @@ -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)


Expand Down

0 comments on commit 3a9a9c9

Please sign in to comment.