mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Motion blinds improve async_request_position_till_stop (#93304)
This commit is contained in:
parent
85a9654e52
commit
2702124130
@ -28,4 +28,6 @@ SERVICE_SET_ABSOLUTE_POSITION = "set_absolute_position"
|
|||||||
|
|
||||||
UPDATE_INTERVAL = 600
|
UPDATE_INTERVAL = 600
|
||||||
UPDATE_INTERVAL_FAST = 60
|
UPDATE_INTERVAL_FAST = 60
|
||||||
|
UPDATE_DELAY_STOP = 3
|
||||||
UPDATE_INTERVAL_MOVING = 5
|
UPDATE_INTERVAL_MOVING = 5
|
||||||
|
UPDATE_INTERVAL_MOVING_WIFI = 45
|
||||||
|
@ -15,7 +15,7 @@ from homeassistant.components.cover import (
|
|||||||
CoverEntityFeature,
|
CoverEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
config_validation as cv,
|
config_validation as cv,
|
||||||
device_registry as dr,
|
device_registry as dr,
|
||||||
@ -36,7 +36,9 @@ from .const import (
|
|||||||
KEY_VERSION,
|
KEY_VERSION,
|
||||||
MANUFACTURER,
|
MANUFACTURER,
|
||||||
SERVICE_SET_ABSOLUTE_POSITION,
|
SERVICE_SET_ABSOLUTE_POSITION,
|
||||||
|
UPDATE_DELAY_STOP,
|
||||||
UPDATE_INTERVAL_MOVING,
|
UPDATE_INTERVAL_MOVING,
|
||||||
|
UPDATE_INTERVAL_MOVING_WIFI,
|
||||||
)
|
)
|
||||||
from .gateway import device_name
|
from .gateway import device_name
|
||||||
|
|
||||||
@ -191,13 +193,15 @@ class MotionPositionDevice(CoordinatorEntity, CoverEntity):
|
|||||||
|
|
||||||
self._blind = blind
|
self._blind = blind
|
||||||
self._api_lock = coordinator.api_lock
|
self._api_lock = coordinator.api_lock
|
||||||
self._requesting_position = False
|
self._requesting_position: CALLBACK_TYPE | None = None
|
||||||
self._previous_positions = []
|
self._previous_positions = []
|
||||||
|
|
||||||
if blind.device_type in DEVICE_TYPES_WIFI:
|
if blind.device_type in DEVICE_TYPES_WIFI:
|
||||||
|
self._update_interval_moving = UPDATE_INTERVAL_MOVING_WIFI
|
||||||
via_device = ()
|
via_device = ()
|
||||||
connections = {(dr.CONNECTION_NETWORK_MAC, blind.mac)}
|
connections = {(dr.CONNECTION_NETWORK_MAC, blind.mac)}
|
||||||
else:
|
else:
|
||||||
|
self._update_interval_moving = UPDATE_INTERVAL_MOVING
|
||||||
via_device = (DOMAIN, blind._gateway.mac)
|
via_device = (DOMAIN, blind._gateway.mac)
|
||||||
connections = {}
|
connections = {}
|
||||||
sw_version = None
|
sw_version = None
|
||||||
@ -271,23 +275,29 @@ class MotionPositionDevice(CoordinatorEntity, CoverEntity):
|
|||||||
self.current_cover_position == prev_position
|
self.current_cover_position == prev_position
|
||||||
for prev_position in self._previous_positions
|
for prev_position in self._previous_positions
|
||||||
):
|
):
|
||||||
# keep updating the position @UPDATE_INTERVAL_MOVING until the position does not change.
|
# keep updating the position @self._update_interval_moving until the position does not change.
|
||||||
async_call_later(
|
self._requesting_position = async_call_later(
|
||||||
self.hass, UPDATE_INTERVAL_MOVING, self.async_scheduled_update_request
|
self.hass,
|
||||||
|
self._update_interval_moving,
|
||||||
|
self.async_scheduled_update_request,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self._previous_positions = []
|
self._previous_positions = []
|
||||||
self._requesting_position = False
|
self._requesting_position = None
|
||||||
|
|
||||||
|
async def async_request_position_till_stop(self, delay=None):
|
||||||
|
"""Request the position of the blind every self._update_interval_moving seconds until it stops moving."""
|
||||||
|
if delay is None:
|
||||||
|
delay = self._update_interval_moving
|
||||||
|
|
||||||
async def async_request_position_till_stop(self):
|
|
||||||
"""Request the position of the blind every UPDATE_INTERVAL_MOVING seconds until it stops moving."""
|
|
||||||
self._previous_positions = []
|
self._previous_positions = []
|
||||||
if self._requesting_position or self.current_cover_position is None:
|
if self.current_cover_position is None:
|
||||||
return
|
return
|
||||||
|
if self._requesting_position is not None:
|
||||||
|
self._requesting_position()
|
||||||
|
|
||||||
self._requesting_position = True
|
self._requesting_position = async_call_later(
|
||||||
async_call_later(
|
self.hass, delay, self.async_scheduled_update_request
|
||||||
self.hass, UPDATE_INTERVAL_MOVING, self.async_scheduled_update_request
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
@ -334,6 +344,8 @@ class MotionPositionDevice(CoordinatorEntity, CoverEntity):
|
|||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Stop)
|
await self.hass.async_add_executor_job(self._blind.Stop)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop(delay=UPDATE_DELAY_STOP)
|
||||||
|
|
||||||
|
|
||||||
class MotionTiltDevice(MotionPositionDevice):
|
class MotionTiltDevice(MotionPositionDevice):
|
||||||
"""Representation of a Motion Blind Device."""
|
"""Representation of a Motion Blind Device."""
|
||||||
@ -378,6 +390,8 @@ class MotionTiltDevice(MotionPositionDevice):
|
|||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Stop)
|
await self.hass.async_add_executor_job(self._blind.Stop)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop(delay=UPDATE_DELAY_STOP)
|
||||||
|
|
||||||
|
|
||||||
class MotionTiltOnlyDevice(MotionTiltDevice):
|
class MotionTiltOnlyDevice(MotionTiltDevice):
|
||||||
"""Representation of a Motion Blind Device."""
|
"""Representation of a Motion Blind Device."""
|
||||||
@ -507,3 +521,5 @@ class MotionTDBUDevice(MotionPositionDevice):
|
|||||||
"""Stop the cover."""
|
"""Stop the cover."""
|
||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
await self.hass.async_add_executor_job(self._blind.Stop, self._motor_key)
|
await self.hass.async_add_executor_job(self._blind.Stop, self._motor_key)
|
||||||
|
|
||||||
|
await self.async_request_position_till_stop(delay=UPDATE_DELAY_STOP)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user