mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 18:18:21 +00:00
Update after Motion Blinds tilt change (#149779)
This commit is contained in:
parent
d77a3fca83
commit
bc87140a6f
@ -289,17 +289,23 @@ class MotionTiltDevice(MotionPositionDevice):
|
|||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Set_angle, 180)
|
await self.hass.async_add_executor_job(self._blind.Set_angle, 180)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop()
|
||||||
|
|
||||||
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
||||||
"""Close the cover tilt."""
|
"""Close the cover tilt."""
|
||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Set_angle, 0)
|
await self.hass.async_add_executor_job(self._blind.Set_angle, 0)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop()
|
||||||
|
|
||||||
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
|
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
|
||||||
"""Move the cover tilt to a specific position."""
|
"""Move the cover tilt to a specific position."""
|
||||||
angle = kwargs[ATTR_TILT_POSITION] * 180 / 100
|
angle = kwargs[ATTR_TILT_POSITION] * 180 / 100
|
||||||
async with self._api_lock:
|
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)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop()
|
||||||
|
|
||||||
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
|
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
|
||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
@ -360,11 +366,15 @@ class MotionTiltOnlyDevice(MotionTiltDevice):
|
|||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Open)
|
await self.hass.async_add_executor_job(self._blind.Open)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop()
|
||||||
|
|
||||||
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
||||||
"""Close the cover tilt."""
|
"""Close the cover tilt."""
|
||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Close)
|
await self.hass.async_add_executor_job(self._blind.Close)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop()
|
||||||
|
|
||||||
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
|
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
|
||||||
"""Move the cover tilt to a specific position."""
|
"""Move the cover tilt to a specific position."""
|
||||||
angle = kwargs[ATTR_TILT_POSITION]
|
angle = kwargs[ATTR_TILT_POSITION]
|
||||||
@ -376,6 +386,8 @@ class MotionTiltOnlyDevice(MotionTiltDevice):
|
|||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Set_position, angle)
|
await self.hass.async_add_executor_job(self._blind.Set_position, angle)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop()
|
||||||
|
|
||||||
async def async_set_absolute_position(self, **kwargs):
|
async def async_set_absolute_position(self, **kwargs):
|
||||||
"""Move the cover to a specific absolute position (see TDBU)."""
|
"""Move the cover to a specific absolute position (see TDBU)."""
|
||||||
angle = kwargs.get(ATTR_TILT_POSITION)
|
angle = kwargs.get(ATTR_TILT_POSITION)
|
||||||
@ -390,6 +402,8 @@ class MotionTiltOnlyDevice(MotionTiltDevice):
|
|||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Set_position, angle)
|
await self.hass.async_add_executor_job(self._blind.Set_position, angle)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop()
|
||||||
|
|
||||||
|
|
||||||
class MotionTDBUDevice(MotionBaseDevice):
|
class MotionTDBUDevice(MotionBaseDevice):
|
||||||
"""Representation of a Motion Top Down Bottom Up blind Device."""
|
"""Representation of a Motion Top Down Bottom Up blind Device."""
|
||||||
|
@ -42,6 +42,7 @@ class MotionCoordinatorEntity(CoordinatorEntity[DataUpdateCoordinatorMotionBlind
|
|||||||
|
|
||||||
self._requesting_position: CALLBACK_TYPE | None = None
|
self._requesting_position: CALLBACK_TYPE | None = None
|
||||||
self._previous_positions: list[int | dict | None] = []
|
self._previous_positions: list[int | dict | None] = []
|
||||||
|
self._previous_angles: list[int | None] = []
|
||||||
|
|
||||||
if blind.device_type in DEVICE_TYPES_WIFI:
|
if blind.device_type in DEVICE_TYPES_WIFI:
|
||||||
self._update_interval_moving = UPDATE_INTERVAL_MOVING_WIFI
|
self._update_interval_moving = UPDATE_INTERVAL_MOVING_WIFI
|
||||||
@ -112,17 +113,27 @@ class MotionCoordinatorEntity(CoordinatorEntity[DataUpdateCoordinatorMotionBlind
|
|||||||
"""Request a state update from the blind at a scheduled point in time."""
|
"""Request a state update from the blind at a scheduled point in time."""
|
||||||
# add the last position to the list and keep the list at max 2 items
|
# add the last position to the list and keep the list at max 2 items
|
||||||
self._previous_positions.append(self._blind.position)
|
self._previous_positions.append(self._blind.position)
|
||||||
|
self._previous_angles.append(self._blind.angle)
|
||||||
if len(self._previous_positions) > 2:
|
if len(self._previous_positions) > 2:
|
||||||
del self._previous_positions[: len(self._previous_positions) - 2]
|
del self._previous_positions[: len(self._previous_positions) - 2]
|
||||||
|
if len(self._previous_angles) > 2:
|
||||||
|
del self._previous_angles[: len(self._previous_angles) - 2]
|
||||||
|
|
||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Update_trigger)
|
await self.hass.async_add_executor_job(self._blind.Update_trigger)
|
||||||
|
|
||||||
self.coordinator.async_update_listeners()
|
self.coordinator.async_update_listeners()
|
||||||
|
|
||||||
if len(self._previous_positions) < 2 or not all(
|
if (
|
||||||
|
len(self._previous_positions) < 2
|
||||||
|
or not all(
|
||||||
self._blind.position == prev_position
|
self._blind.position == prev_position
|
||||||
for prev_position in self._previous_positions
|
for prev_position in self._previous_positions
|
||||||
|
)
|
||||||
|
or len(self._previous_angles) < 2
|
||||||
|
or not all(
|
||||||
|
self._blind.angle == prev_angle for prev_angle in self._previous_angles
|
||||||
|
)
|
||||||
):
|
):
|
||||||
# keep updating the position @self._update_interval_moving until the position does not change.
|
# keep updating the position @self._update_interval_moving until the position does not change.
|
||||||
self._requesting_position = async_call_later(
|
self._requesting_position = async_call_later(
|
||||||
@ -132,6 +143,7 @@ class MotionCoordinatorEntity(CoordinatorEntity[DataUpdateCoordinatorMotionBlind
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self._previous_positions = []
|
self._previous_positions = []
|
||||||
|
self._previous_angles = []
|
||||||
self._requesting_position = None
|
self._requesting_position = None
|
||||||
|
|
||||||
async def async_request_position_till_stop(self, delay: int | None = None) -> None:
|
async def async_request_position_till_stop(self, delay: int | None = None) -> None:
|
||||||
@ -140,7 +152,8 @@ class MotionCoordinatorEntity(CoordinatorEntity[DataUpdateCoordinatorMotionBlind
|
|||||||
delay = self._update_interval_moving
|
delay = self._update_interval_moving
|
||||||
|
|
||||||
self._previous_positions = []
|
self._previous_positions = []
|
||||||
if self._blind.position is None:
|
self._previous_angles = []
|
||||||
|
if self._blind.position is None and self._blind.angle is None:
|
||||||
return
|
return
|
||||||
if self._requesting_position is not None:
|
if self._requesting_position is not None:
|
||||||
self._requesting_position()
|
self._requesting_position()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user