Refactor sensor and binary sensor setup to use async_add_entities with update_before_add=True
This commit is contained in:
parent
eb716dafe9
commit
c07780ac95
@ -35,8 +35,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
"coordinator": coordinator,
|
"coordinator": coordinator,
|
||||||
"session": session
|
"session": session
|
||||||
}
|
}
|
||||||
await hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
await hass.config_entries.async_forward_entry_setups(entry, ["sensor","binary_sensor"])
|
||||||
await hass.config_entries.async_forward_entry_setup(entry, "binary_sensor")
|
|
||||||
# hass.async_create_task(
|
# hass.async_create_task(
|
||||||
# hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
# hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
||||||
# )
|
# )
|
||||||
@ -45,5 +44,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
await hass.data[DOMAIN][entry.entry_id]["session"].close()
|
await hass.data[DOMAIN][entry.entry_id]["session"].close()
|
||||||
await hass.config_entries.async_forward_entry_unload(entry, "sensor")
|
return await hass.config_entries.async_unload_platforms(entry, ["binary_sensor","sensor"])
|
||||||
return await hass.config_entries.async_forward_entry_unload(entry, "binary_sensor")
|
|
||||||
|
|||||||
@ -75,7 +75,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
async_add_entities(sensors)
|
async_add_entities(sensors, update_before_add=True)
|
||||||
|
|
||||||
class Sensor(CoordinatorEntity, BinarySensorEntity):
|
class Sensor(CoordinatorEntity, BinarySensorEntity):
|
||||||
def __init__(self, coordinator, deviceinfo, entry_id, id, family_key, device_key, name, device_class, state_class, native_unit_of_measurement, subkey=None):
|
def __init__(self, coordinator, deviceinfo, entry_id, id, family_key, device_key, name, device_class, state_class, native_unit_of_measurement, subkey=None):
|
||||||
|
|||||||
@ -279,7 +279,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
async_add_entities(sensors)
|
async_add_entities(sensors, update_before_add=True)
|
||||||
|
|
||||||
class Sensor(CoordinatorEntity, SensorEntity):
|
class Sensor(CoordinatorEntity, SensorEntity):
|
||||||
def __init__(self, coordinator, deviceinfo, entry_id, id, family_key, device_key, name, device_class, state_class, native_unit_of_measurement, subkey=None):
|
def __init__(self, coordinator, deviceinfo, entry_id, id, family_key, device_key, name, device_class, state_class, native_unit_of_measurement, subkey=None):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user