Skip to content

Commit

Permalink
switch from coroutine to async/await
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
andnp committed Jun 8, 2023
1 parent 398ac4c commit 31f3725
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions custom_components/attributes/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 31f3725

Please sign in to comment.