Update to sense component to fully be async (#21698)
* Update to sense component to fully be async * Shortened lines * Whitespace
This commit is contained in:
parent
dd11f8d3fe
commit
62df6cbd09
4 changed files with 26 additions and 28 deletions
|
@ -49,17 +49,15 @@ MDI_ICONS = {
|
|||
}
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Sense binary sensor."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
data = hass.data[SENSE_DATA]
|
||||
|
||||
sense_devices = data.get_discovered_device_data()
|
||||
sense_devices = await data.get_discovered_device_data()
|
||||
devices = [SenseDevice(data, device) for device in sense_devices
|
||||
if device['tags']['DeviceListAllowed'] == 'true']
|
||||
add_entities(devices)
|
||||
async_add_entities(devices)
|
||||
|
||||
|
||||
def sense_to_mdi(sense_icon):
|
||||
|
@ -103,11 +101,11 @@ class SenseDevice(BinarySensorDevice):
|
|||
"""Return the device class of the binary sensor."""
|
||||
return BIN_SENSOR_CLASS
|
||||
|
||||
def update(self):
|
||||
async def async_update(self):
|
||||
"""Retrieve latest state."""
|
||||
from sense_energy.sense_api import SenseAPITimeoutException
|
||||
try:
|
||||
self._data.get_realtime()
|
||||
await self._data.update_realtime()
|
||||
except SenseAPITimeoutException:
|
||||
_LOGGER.error("Timeout retrieving data")
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue