Use Position instead of Angle for TiltOnlyDevice in motion blinds (#123521)

Use Position instead of Angle for TiltOnlyBlinds
This commit is contained in:
starkillerOG 2024-08-28 11:27:34 +02:00 committed by GitHub
parent c772c4a2d5
commit 10b3119b4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -330,23 +330,63 @@ class MotionTiltOnlyDevice(MotionTiltDevice):
"""Return current position of cover."""
return None
@property
def current_cover_tilt_position(self) -> int | None:
"""Return current angle of cover.
None is unknown, 0 is closed/minimum tilt, 100 is fully open/maximum tilt.
"""
if self._blind.position is None:
if self._blind.angle is None:
return None
return self._blind.angle * 100 / 180
return self._blind.position
@property
def is_closed(self) -> bool | None:
"""Return if the cover is closed or not."""
if self._blind.angle is None:
return None
return self._blind.angle == 0
if self._blind.position is None:
if self._blind.angle is None:
return None
return self._blind.angle == 0
return self._blind.position == 0
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
"""Open the cover tilt."""
async with self._api_lock:
await self.hass.async_add_executor_job(self._blind.Open)
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
"""Close the cover tilt."""
async with self._api_lock:
await self.hass.async_add_executor_job(self._blind.Close)
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
"""Move the cover tilt to a specific position."""
angle = kwargs[ATTR_TILT_POSITION]
if self._blind.position is None:
angle = angle * 180 / 100
async with self._api_lock:
await self.hass.async_add_executor_job(self._blind.Set_angle, angle)
else:
async with self._api_lock:
await self.hass.async_add_executor_job(self._blind.Set_position, angle)
async def async_set_absolute_position(self, **kwargs):
"""Move the cover to a specific absolute position (see TDBU)."""
angle = kwargs.get(ATTR_TILT_POSITION)
if angle is not None:
if angle is None:
return
if self._blind.position is None:
angle = angle * 180 / 100
async with self._api_lock:
await self.hass.async_add_executor_job(
self._blind.Set_angle,
angle,
)
await self.hass.async_add_executor_job(self._blind.Set_angle, angle)
else:
async with self._api_lock:
await self.hass.async_add_executor_job(self._blind.Set_position, angle)
class MotionTDBUDevice(MotionBaseDevice):