Skip to content

Commit

Permalink
Fix threading issues. (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
twrecked authored Aug 16, 2024
1 parent 62a5358 commit 7208097
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 2 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/virtual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .cfg import BlendedCfg, UpgradeCfg


__version__ = '0.9.0b14'
__version__ = '0.9.0b15'

_LOGGER = logging.getLogger(__name__)

Expand Down
8 changes: 4 additions & 4 deletions custom_components/virtual/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
11 changes: 5 additions & 6 deletions custom_components/virtual/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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:
Expand All @@ -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)
2 changes: 1 addition & 1 deletion custom_components/virtual/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
9 changes: 4 additions & 5 deletions custom_components/virtual/valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 7208097

Please sign in to comment.