Support fibaro garage door devices (#72299)

* Add proper support for garage door controller in fibaro cover entity

* Add proper support for garage door controller in fibaro cover entity
This commit is contained in:
rappenze 2022-05-24 16:00:15 +02:00 committed by GitHub
parent 6368df5e37
commit 1113d9bea9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ from homeassistant.components.cover import (
ATTR_TILT_POSITION,
ENTITY_ID_FORMAT,
CoverEntity,
CoverEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
@ -41,6 +42,11 @@ class FibaroCover(FibaroDevice, CoverEntity):
super().__init__(fibaro_device)
self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id)
if self._is_open_close_only():
self._attr_supported_features = (
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
)
@staticmethod
def bound(position):
"""Normalize the position."""
@ -53,6 +59,14 @@ class FibaroCover(FibaroDevice, CoverEntity):
return 100
return position
def _is_open_close_only(self) -> bool:
"""Return if only open / close is supported."""
# Normally positionable devices report the position over value,
# so if it is missing we have a device which supports open / close only
if "value" not in self.fibaro_device.properties:
return True
return False
@property
def current_cover_position(self):
"""Return current position of cover. 0 is closed, 100 is open."""
@ -74,6 +88,9 @@ class FibaroCover(FibaroDevice, CoverEntity):
@property
def is_closed(self):
"""Return if the cover is closed."""
if self._is_open_close_only():
return self.fibaro_device.properties.state.lower() == "closed"
if self.current_cover_position is None:
return None
return self.current_cover_position == 0