From 2d6a6c982be8c196f8b8d9c08aaf9255bf48194b Mon Sep 17 00:00:00 2001 From: PatrickFulcheri <33725895+PatrickFulcheri@users.noreply.github.com> Date: Wed, 15 May 2024 17:24:56 +0200 Subject: [PATCH] Update sensor.py to remove async_create_task not supported form HA 2024.5 Not expert, but tested and working. Reference is https://developers.home-assistant.io/docs/asyncio_thread_safety --- custom_components/powerlink2/sensor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/powerlink2/sensor.py b/custom_components/powerlink2/sensor.py index 14e639f..67e2d7a 100644 --- a/custom_components/powerlink2/sensor.py +++ b/custom_components/powerlink2/sensor.py @@ -231,7 +231,7 @@ def do_getstatus(self): if self._alarm_status != new_status: self._state = new_status self._alarm_status = new_status - self.hass.async_create_task(mqtt.async_publish(self.hass, self._state_topic, self._alarm_status, self._qos, True)) + self.hass.create_task(mqtt.async_publish(self.hass, self._state_topic, self._alarm_status, self._qos, True)) _LOGGER.info("Alarm status: %s for topic %s ",self._alarm_status,self._state_topic) self._status_last_sent = time.time() _LOGGER.debug("Index: " + str(self._curr_index)) @@ -271,10 +271,10 @@ def do_sensor_check(self): # Workaround for boolean sensor status = STATE_OPEN if battery != BATTERY_UNDETERMINED: - self.hass.async_create_task(mqtt.async_publish(self.hass, self._battery_topic + zone, battery, self._qos, True)) + self.hass.create_task(mqtt.async_publish(self.hass, self._battery_topic + zone, battery, self._qos, True)) _LOGGER.info("Setting battery to " + str(battery) + " for topic " + str(self._battery_topic + zone)) if battery != BATTERY_LOW: - self.hass.async_create_task(mqtt.async_publish(self.hass, self._sensor_topic + zone, status, self._qos, True)) + self.hass.create_task(mqtt.async_publish(self.hass, self._sensor_topic + zone, status, self._qos, True)) _LOGGER.info("Setting state to " + str(status) + " for topic " + str(self._sensor_topic + zone)) def do_setstatus(self, target_status): @@ -332,7 +332,7 @@ async def _async_state_changed_listener(self, event): new_state = event.data.get("new_state") if new_state is None: return - self.hass.async_create_task(mqtt.async_publish(self.hass, self._state_topic, new_state.state, self._qos, True)) + self.hass.create_task(mqtt.async_publish(self.hass, self._state_topic, new_state.state, self._qos, True)) _LOGGER.info("state changed %s topic %s",str(new_state),self._state_topic) return