diff --git a/custom_components/duofern/__init__.py b/custom_components/duofern/__init__.py index 5d70664..a1eb001 100644 --- a/custom_components/duofern/__init__.py +++ b/custom_components/duofern/__init__.py @@ -118,6 +118,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: stick = DuofernStickThreaded(serial_port=serial_port, system_code=code, config_file_json=configfile, ephemeral=False) + stick.updating_interval = 5*60 _registerServices(hass, stick, configEntries[0]) _registerUpdateHassFromStickCallback(hass, stick) @@ -149,7 +150,7 @@ def _registerUpdateHassFromStickCallback(hass: HomeAssistant, stick: DuofernStic def update_callback(id: str | None, key: Any, value: Any) -> None: if id is not None: try: - _LOGGER.info(f"Updatecallback for {id}") + _LOGGER.debug(f"Updatecallback for {id}: {key}: {value}") device = hass.data[DOMAIN]['devices'][id] # Get device by id if device.enabled: try: @@ -196,7 +197,8 @@ def get_device_id(hass_entity_id): hass_device_id = call.data.get('device_id', None) if get_all: _LOGGER.info("Asking all devices for update") - device_ids = hass.data[DOMAIN]['stick'].duofern_parser.modules['by_code'].keys() + hass.data[DOMAIN]['stick'].status_request() + return else: _LOGGER.info("Asking specific devices for update") device_ids = [get_device_id(i) for i in hass_device_id] @@ -224,13 +226,13 @@ def get_device_id(hass_entity_id): def set_update_interval(call: ServiceCall) -> None: try: period_minutes = call.data.get('period_minutes', None) - if period_minutes == int(0): + if period_minutes == 0: period_minutes = None _LOGGER.warning("set period_minutes to 0 - no updates will be triggered automatically") except Exception: _LOGGER.warning("something went wrong while reading period from parameters") return - getDuofernStick(hass).updating_interval = period_minutes + getDuofernStick(hass).updating_interval = period_minutes*60 if period_minutes is not None else None PAIRING_SCHEMA = vol.Schema({ vol.Optional('timeout', default=30): cv.positive_int, @@ -242,7 +244,7 @@ def set_update_interval(call: ServiceCall) -> None: }) UPDATE_INTERVAL_SCHEMA = vol.Schema({ - vol.Optional('period_minutes', default=5): cv.positive_int, + vol.Optional('period_minutes', default=5): cv.positive_float, }) hass.services.register(DOMAIN, 'start_pairing', start_pairing, PAIRING_SCHEMA) diff --git a/custom_components/duofern/cover.py b/custom_components/duofern/cover.py index f5c6d9c..e0b68d2 100644 --- a/custom_components/duofern/cover.py +++ b/custom_components/duofern/cover.py @@ -75,7 +75,6 @@ def __init__(self, duofernId: str, name: str, stick: DuofernStickThreaded): self._stick = stick self._openclose: Literal["up", "down", "stop"] = 'stop' self._last_update_time = datetime.datetime.now() - self._stick.updating_interval = 5 @property def name(self) -> str: @@ -111,7 +110,7 @@ def is_closed(self) -> bool | None: @property def should_poll(self) -> bool: """Whether this entity should be polled or uses subscriptions""" - return True # TODO: Add config option for subscriptions over polling + return False # TODO: Add config option for subscriptions over polling @property def supported_features(self) -> CoverEntityFeature: @@ -168,8 +167,4 @@ def update(self) -> None: self._openclose = self._stick.duofern_parser.modules['by_code'][self._duofernId]['moving'] except KeyError: self._state = None - if self._stick.updating_interval is not None and \ - datetime.datetime.now() - self._last_update_time > datetime.timedelta(minutes=self._stick.updating_interval): - self._stick.command(self._duofernId, 'getStatus') - self._last_update_time = datetime.datetime.now() + datetime.timedelta(seconds=randint(0, 60)) _LOGGER.info(f"{self._duofernId} state is now {self._state}") diff --git a/custom_components/duofern/manifest.json b/custom_components/duofern/manifest.json index 536467c..c085bd5 100644 --- a/custom_components/duofern/manifest.json +++ b/custom_components/duofern/manifest.json @@ -6,6 +6,6 @@ "config_flow": true, "issue_tracker": "https://github.com/gluap/pyduofern-hacs/issues" , "codeowners": ["@gluap"], - "requirements": ["pyduofern==0.36.1"], + "requirements": ["pyduofern==0.36.2"], "version": "0.5.16" } diff --git a/custom_components/duofern/services.yaml b/custom_components/duofern/services.yaml index bb17c17..3ee2578 100644 --- a/custom_components/duofern/services.yaml +++ b/custom_components/duofern/services.yaml @@ -39,9 +39,10 @@ set_update_interval: fields: period_minutes: description: approximate forced refresh interval in minutes - defaults to 5, 0 means never - example: 5 + example: 5.0 required: true selector: number: - min: 0 - max: 60 + min: 0.0 + max: 10.0 + step: 0.1