diff --git a/changelog b/changelog index ef7ea0f..01a21a3 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,5 @@ +0.9.0b15: + Fix threading issue with cover and valve. 0.9.0b14: Restore previous YAML config support. 0.9.0b13: diff --git a/custom_components/virtual/__init__.py b/custom_components/virtual/__init__.py index cbc894a..090478f 100644 --- a/custom_components/virtual/__init__.py +++ b/custom_components/virtual/__init__.py @@ -30,7 +30,7 @@ from .cfg import BlendedCfg, UpgradeCfg -__version__ = '0.9.0b14' +__version__ = '0.9.0b15' _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/virtual/cover.py b/custom_components/virtual/cover.py index e0e62db..319db74 100644 --- a/custom_components/virtual/cover.py +++ b/custom_components/virtual/cover.py @@ -86,18 +86,18 @@ def __init__(self, config, old_style : bool): def current_cover_position(self) -> int | None: return self._current_position - def open_cover(self, **kwargs: Any) -> None: + async def async_open_cover(self, **kwargs: Any) -> None: _LOGGER.info(f"opening {self.name}") self._set_position(100) - def close_cover(self, **kwargs: Any) -> None: + async def async_close_cover(self, **kwargs: Any) -> None: _LOGGER.info(f"closing {self.name}") self._set_position(0) - def stop_cover(self, **kwargs: Any) -> None: + async def async_stop_cover(self, **kwargs: Any) -> None: _LOGGER.info(f"stopping {self.name}") self._stop() - def set_cover_position(self, **kwargs: Any) -> None: + async def async_set_cover_position(self, **kwargs: Any) -> None: _LOGGER.info(f"setting {self.name} position {kwargs['position']}") self._set_position(kwargs['position']) diff --git a/custom_components/virtual/entity.py b/custom_components/virtual/entity.py index 770d539..3e742e2 100644 --- a/custom_components/virtual/entity.py +++ b/custom_components/virtual/entity.py @@ -195,7 +195,7 @@ def _stop(self) -> None: else: self._attr_is_closed = True - self.schedule_update_ha_state() + self.async_write_ha_state() def _set_position(self, position) -> None: _LOGGER.info(f"setting {self.name} position {position}") @@ -209,8 +209,10 @@ def _set_position(self, position) -> None: else: self._attr_is_opening = True self._attr_is_closing = False - self._tick() - self.schedule_update_ha_state() + + self.async_write_ha_state() + self._open_close_operation_started = datetime.now() + async_call_later(self.hass, self._open_close_tick, self._update_position) @callback def _update_position(self, _now) -> None: @@ -233,8 +235,5 @@ def _update_position(self, _now) -> None: self._current_position = min(100, self._current_position + percent_moved) self.async_write_ha_state() - self._tick() - - def _tick(self): self._open_close_operation_started = datetime.now() async_call_later(self.hass, self._open_close_tick, self._update_position) diff --git a/custom_components/virtual/manifest.json b/custom_components/virtual/manifest.json index 4cbb19a..8acb6cb 100644 --- a/custom_components/virtual/manifest.json +++ b/custom_components/virtual/manifest.json @@ -8,5 +8,5 @@ "documentation": "https://github.com/twrecked/hass-virtual/blob/master/README.md", "iot_class": "local_push", "issue_tracker": "https://github.com/twrecked/hass-virtual/issues", - "version": "0.9.0b14" + "version": "0.9.0b15" } diff --git a/custom_components/virtual/valve.py b/custom_components/virtual/valve.py index 84f5ab0..527e688 100644 --- a/custom_components/virtual/valve.py +++ b/custom_components/virtual/valve.py @@ -5,7 +5,6 @@ import logging import voluptuous as vol -from typing import Any from collections.abc import Callable import homeassistant.helpers.config_validation as cv @@ -93,18 +92,18 @@ def __init__(self, config, old_style: bool): def current_valve_position(self) -> int | None: return self._current_position - def open_valve(self, **kwargs: Any) -> None: + async def async_open_valve(self) -> None: _LOGGER.info(f"opening {self.name}") self._set_position(100) - def close_valve(self, **kwargs: Any) -> None: + async def async_close_valve(self) -> None: _LOGGER.info(f"closing {self.name}") self._set_position(0) - def stop_valve(self, **kwargs: Any) -> None: + async def async_stop_valve(self) -> None: _LOGGER.info(f"stopping {self.name}") self._stop() - def set_valve_position(self, position: int) -> None: + async def async_set_valve_position(self, position: int) -> None: _LOGGER.info(f"setting {self.name} position {position}") self._set_position(position)