Skip to content

Commit

Permalink
Use Position instead of Angle for TiltOnlyDevice in motion blinds (#1…
Browse files Browse the repository at this point in the history
…23521)

Use Position instead of Angle for TiltOnlyBlinds
  • Loading branch information
starkillerOG authored Aug 28, 2024
1 parent c772c4a commit 10b3119
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions homeassistant/components/motion_blinds/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,63 @@ def current_cover_position(self) -> None:
"""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):
Expand Down

0 comments on commit 10b3119

Please sign in to comment.