From 46892e3d570f29b29ab16151c6e61c99ef973cfc Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Sat, 29 Feb 2020 10:34:04 -0500 Subject: [PATCH] Only use one cover type per device resolves #22 --- custom_components/hubitat/cover.py | 33 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/custom_components/hubitat/cover.py b/custom_components/hubitat/cover.py index 6c0d413..122a51c 100644 --- a/custom_components/hubitat/cover.py +++ b/custom_components/hubitat/cover.py @@ -1,5 +1,5 @@ from logging import getLogger -from typing import Any, Optional, Tuple, Type +from typing import Any, List, Optional from hubitatmaker import ( ATTR_DOOR, @@ -72,6 +72,11 @@ def supported_features(self) -> int: """Flag supported features.""" return self._features + @property + def unique_id(self) -> str: + """Return a unique ID for this sensor.""" + return f"{super().unique_id}::{self._attribute}" + async def async_close_cover(self, **kwargs: Any) -> None: """Close the cover.""" _LOGGER.debug("Closing %s", self.name) @@ -122,26 +127,22 @@ def __init__(self, *args: Any, **kwargs: Any): self._features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION -_COVER_CAPS: Tuple[Tuple[str, Type[HubitatCover]], ...] = ( - (CAP_DOOR_CONTROL, HubitatDoorControl), - (CAP_GARAGE_DOOR_CONTROL, HubitatGarageDoorControl), - (CAP_WINDOW_SHADE, HubitatWindowShade), -) - - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities, ) -> None: """Initialize cover devices.""" hub = get_hub(hass, entry.entry_id) - devices = hub.devices - - for (cap, Cover) in _COVER_CAPS: - covers = [ - Cover(hub=hub, device=devices[i]) - for i in devices - if cap in devices[i].capabilities - ] + covers: List[HubitatCover] = [] + + for dev in hub.devices.values(): + if CAP_WINDOW_SHADE in dev.capabilities: + covers.append(HubitatWindowShade(hub=hub, device=dev)) + elif CAP_GARAGE_DOOR_CONTROL in dev.capabilities: + covers.append(HubitatGarageDoorControl(hub=hub, device=dev)) + elif CAP_DOOR_CONTROL in dev.capabilities: + covers.append(HubitatDoorControl(hub=hub, device=dev)) + + if len(covers) > 0: async_add_entities(covers) hub.add_entities(covers) _LOGGER.debug(f"Added entities for covers: {covers}")