From 31f3725fa042ebb2de712b4fa07a8b62b0d654ac Mon Sep 17 00:00:00 2001 From: Andy Patterson Date: Wed, 7 Jun 2023 17:42:46 -0600 Subject: [PATCH] switch from coroutine to async/await With the upgrade to python 3.11, `@asyncio.coroutine` no longer exists. This was preventing the plugin from loading. Switched all instances of `@asyncio.coroutine` to `async def` methods and switched `yield from` to `await`. --- custom_components/attributes/sensor.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/custom_components/attributes/sensor.py b/custom_components/attributes/sensor.py index 98dec2c..5c8792d 100644 --- a/custom_components/attributes/sensor.py +++ b/custom_components/attributes/sensor.py @@ -41,8 +41,12 @@ }) -@asyncio.coroutine -def async_setup_platform(hass, config, async_add_devices, discovery_info=None): +async def async_setup_platform( + hass, + config, + async_add_devices, + discovery_info=None +): """Set up the attributes sensors.""" _LOGGER.info("Starting attribute sensor") sensors = [] @@ -200,10 +204,9 @@ def __init__(self, hass, device_id, friendly_name, device_friendly_name, self._icon = None self._entity = entity_id - @asyncio.coroutine - def async_added_to_hass(self): + async def async_added_to_hass(self): """Register callbacks.""" - state = yield from self.async_get_last_state() + state = await self.async_get_last_state() if state: self._state = state.state @@ -258,8 +261,7 @@ def should_poll(self): """No polling needed.""" return False - @asyncio.coroutine - def async_update(self): + async def async_update(self): """Update the state from the template and the friendly name.""" entity_state = self.hass.states.get(self._entity)