Clean up Shelly async methods that are not awaiting (#72026)
This commit is contained in:
parent
c0da97b038
commit
0d94324d58
10 changed files with 58 additions and 45 deletions
|
@ -182,7 +182,7 @@ async def async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> bo
|
|||
data["model"] = device.settings["device"]["type"]
|
||||
hass.config_entries.async_update_entry(entry, data=data)
|
||||
|
||||
hass.async_create_task(async_block_device_setup(hass, entry, device))
|
||||
async_block_device_setup(hass, entry, device)
|
||||
|
||||
if sleep_period == 0:
|
||||
# Not a sleeping device, finish setup
|
||||
|
@ -197,7 +197,7 @@ async def async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> bo
|
|||
except OSError as err:
|
||||
raise ConfigEntryNotReady(str(err) or "Error during device setup") from err
|
||||
|
||||
await async_block_device_setup(hass, entry, device)
|
||||
async_block_device_setup(hass, entry, device)
|
||||
elif sleep_period is None or device_entry is None:
|
||||
# Need to get sleep info or first time sleeping device setup, wait for device
|
||||
hass.data[DOMAIN][DATA_CONFIG_ENTRY][entry.entry_id][DEVICE] = device
|
||||
|
@ -208,12 +208,13 @@ async def async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> bo
|
|||
else:
|
||||
# Restore sensors for sleeping device
|
||||
LOGGER.debug("Setting up offline block device %s", entry.title)
|
||||
await async_block_device_setup(hass, entry, device)
|
||||
async_block_device_setup(hass, entry, device)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_block_device_setup(
|
||||
@callback
|
||||
def async_block_device_setup(
|
||||
hass: HomeAssistant, entry: ConfigEntry, device: BlockDevice
|
||||
) -> None:
|
||||
"""Set up a block based device that is online."""
|
||||
|
|
|
@ -235,12 +235,12 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up sensors for device."""
|
||||
if get_device_entry_gen(config_entry) == 2:
|
||||
return await async_setup_entry_rpc(
|
||||
return async_setup_entry_rpc(
|
||||
hass, config_entry, async_add_entities, RPC_SENSORS, RpcBinarySensor
|
||||
)
|
||||
|
||||
if config_entry.data[CONF_SLEEP_PERIOD]:
|
||||
await async_setup_entry_attribute_entities(
|
||||
async_setup_entry_attribute_entities(
|
||||
hass,
|
||||
config_entry,
|
||||
async_add_entities,
|
||||
|
@ -249,7 +249,7 @@ async def async_setup_entry(
|
|||
_build_block_description,
|
||||
)
|
||||
else:
|
||||
await async_setup_entry_attribute_entities(
|
||||
async_setup_entry_attribute_entities(
|
||||
hass,
|
||||
config_entry,
|
||||
async_add_entities,
|
||||
|
@ -257,7 +257,7 @@ async def async_setup_entry(
|
|||
BlockBinarySensor,
|
||||
_build_block_description,
|
||||
)
|
||||
await async_setup_entry_rest(
|
||||
async_setup_entry_rest(
|
||||
hass,
|
||||
config_entry,
|
||||
async_add_entities,
|
||||
|
|
|
@ -50,14 +50,13 @@ async def async_setup_entry(
|
|||
][BLOCK]
|
||||
|
||||
if wrapper.device.initialized:
|
||||
await async_setup_climate_entities(async_add_entities, wrapper)
|
||||
async_setup_climate_entities(async_add_entities, wrapper)
|
||||
else:
|
||||
await async_restore_climate_entities(
|
||||
hass, config_entry, async_add_entities, wrapper
|
||||
)
|
||||
async_restore_climate_entities(hass, config_entry, async_add_entities, wrapper)
|
||||
|
||||
|
||||
async def async_setup_climate_entities(
|
||||
@callback
|
||||
def async_setup_climate_entities(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
wrapper: BlockDeviceWrapper,
|
||||
) -> None:
|
||||
|
@ -79,7 +78,8 @@ async def async_setup_climate_entities(
|
|||
async_add_entities([BlockSleepingClimate(wrapper, sensor_block, device_block)])
|
||||
|
||||
|
||||
async def async_restore_climate_entities(
|
||||
@callback
|
||||
def async_restore_climate_entities(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
|
|
@ -28,12 +28,13 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up switches for device."""
|
||||
if get_device_entry_gen(config_entry) == 2:
|
||||
return await async_setup_rpc_entry(hass, config_entry, async_add_entities)
|
||||
return async_setup_rpc_entry(hass, config_entry, async_add_entities)
|
||||
|
||||
return await async_setup_block_entry(hass, config_entry, async_add_entities)
|
||||
return async_setup_block_entry(hass, config_entry, async_add_entities)
|
||||
|
||||
|
||||
async def async_setup_block_entry(
|
||||
@callback
|
||||
def async_setup_block_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
@ -48,7 +49,8 @@ async def async_setup_block_entry(
|
|||
async_add_entities(BlockShellyCover(wrapper, block) for block in blocks)
|
||||
|
||||
|
||||
async def async_setup_rpc_entry(
|
||||
@callback
|
||||
def async_setup_rpc_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
|
|
@ -46,7 +46,8 @@ from .utils import (
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_entry_attribute_entities(
|
||||
@callback
|
||||
def async_setup_entry_attribute_entities(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
@ -62,11 +63,11 @@ async def async_setup_entry_attribute_entities(
|
|||
][BLOCK]
|
||||
|
||||
if wrapper.device.initialized:
|
||||
await async_setup_block_attribute_entities(
|
||||
async_setup_block_attribute_entities(
|
||||
hass, async_add_entities, wrapper, sensors, sensor_class
|
||||
)
|
||||
else:
|
||||
await async_restore_block_attribute_entities(
|
||||
async_restore_block_attribute_entities(
|
||||
hass,
|
||||
config_entry,
|
||||
async_add_entities,
|
||||
|
@ -77,7 +78,8 @@ async def async_setup_entry_attribute_entities(
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_block_attribute_entities(
|
||||
@callback
|
||||
def async_setup_block_attribute_entities(
|
||||
hass: HomeAssistant,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
wrapper: BlockDeviceWrapper,
|
||||
|
@ -105,7 +107,7 @@ async def async_setup_block_attribute_entities(
|
|||
):
|
||||
domain = sensor_class.__module__.split(".")[-1]
|
||||
unique_id = f"{wrapper.mac}-{block.description}-{sensor_id}"
|
||||
await async_remove_shelly_entity(hass, domain, unique_id)
|
||||
async_remove_shelly_entity(hass, domain, unique_id)
|
||||
else:
|
||||
blocks.append((block, sensor_id, description))
|
||||
|
||||
|
@ -120,7 +122,8 @@ async def async_setup_block_attribute_entities(
|
|||
)
|
||||
|
||||
|
||||
async def async_restore_block_attribute_entities(
|
||||
@callback
|
||||
def async_restore_block_attribute_entities(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
@ -158,7 +161,8 @@ async def async_restore_block_attribute_entities(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
async def async_setup_entry_rpc(
|
||||
@callback
|
||||
def async_setup_entry_rpc(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
@ -192,7 +196,7 @@ async def async_setup_entry_rpc(
|
|||
):
|
||||
domain = sensor_class.__module__.split(".")[-1]
|
||||
unique_id = f"{wrapper.mac}-{key}-{sensor_id}"
|
||||
await async_remove_shelly_entity(hass, domain, unique_id)
|
||||
async_remove_shelly_entity(hass, domain, unique_id)
|
||||
else:
|
||||
if description.use_polling_wrapper:
|
||||
entities.append(
|
||||
|
@ -207,7 +211,8 @@ async def async_setup_entry_rpc(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
async def async_setup_entry_rest(
|
||||
@callback
|
||||
def async_setup_entry_rest(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
|
|
@ -65,12 +65,13 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up lights for device."""
|
||||
if get_device_entry_gen(config_entry) == 2:
|
||||
return await async_setup_rpc_entry(hass, config_entry, async_add_entities)
|
||||
return async_setup_rpc_entry(hass, config_entry, async_add_entities)
|
||||
|
||||
return await async_setup_block_entry(hass, config_entry, async_add_entities)
|
||||
return async_setup_block_entry(hass, config_entry, async_add_entities)
|
||||
|
||||
|
||||
async def async_setup_block_entry(
|
||||
@callback
|
||||
def async_setup_block_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
@ -92,7 +93,7 @@ async def async_setup_block_entry(
|
|||
blocks.append(block)
|
||||
assert wrapper.device.shelly
|
||||
unique_id = f"{wrapper.mac}-{block.type}_{block.channel}"
|
||||
await async_remove_shelly_entity(hass, "switch", unique_id)
|
||||
async_remove_shelly_entity(hass, "switch", unique_id)
|
||||
|
||||
if not blocks:
|
||||
return
|
||||
|
@ -100,7 +101,8 @@ async def async_setup_block_entry(
|
|||
async_add_entities(BlockShellyLight(wrapper, block) for block in blocks)
|
||||
|
||||
|
||||
async def async_setup_rpc_entry(
|
||||
@callback
|
||||
def async_setup_rpc_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
@ -116,7 +118,7 @@ async def async_setup_rpc_entry(
|
|||
|
||||
switch_ids.append(id_)
|
||||
unique_id = f"{wrapper.mac}-switch:{id_}"
|
||||
await async_remove_shelly_entity(hass, "switch", unique_id)
|
||||
async_remove_shelly_entity(hass, "switch", unique_id)
|
||||
|
||||
if not switch_ids:
|
||||
return
|
||||
|
|
|
@ -81,7 +81,7 @@ async def async_setup_entry(
|
|||
return
|
||||
|
||||
if config_entry.data[CONF_SLEEP_PERIOD]:
|
||||
await async_setup_entry_attribute_entities(
|
||||
async_setup_entry_attribute_entities(
|
||||
hass,
|
||||
config_entry,
|
||||
async_add_entities,
|
||||
|
|
|
@ -394,12 +394,12 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up sensors for device."""
|
||||
if get_device_entry_gen(config_entry) == 2:
|
||||
return await async_setup_entry_rpc(
|
||||
return async_setup_entry_rpc(
|
||||
hass, config_entry, async_add_entities, RPC_SENSORS, RpcSensor
|
||||
)
|
||||
|
||||
if config_entry.data[CONF_SLEEP_PERIOD]:
|
||||
await async_setup_entry_attribute_entities(
|
||||
async_setup_entry_attribute_entities(
|
||||
hass,
|
||||
config_entry,
|
||||
async_add_entities,
|
||||
|
@ -408,7 +408,7 @@ async def async_setup_entry(
|
|||
_build_block_description,
|
||||
)
|
||||
else:
|
||||
await async_setup_entry_attribute_entities(
|
||||
async_setup_entry_attribute_entities(
|
||||
hass,
|
||||
config_entry,
|
||||
async_add_entities,
|
||||
|
@ -416,7 +416,7 @@ async def async_setup_entry(
|
|||
BlockSensor,
|
||||
_build_block_description,
|
||||
)
|
||||
await async_setup_entry_rest(
|
||||
async_setup_entry_rest(
|
||||
hass, config_entry, async_add_entities, REST_SENSORS, RestSensor
|
||||
)
|
||||
|
||||
|
|
|
@ -29,12 +29,13 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up switches for device."""
|
||||
if get_device_entry_gen(config_entry) == 2:
|
||||
return await async_setup_rpc_entry(hass, config_entry, async_add_entities)
|
||||
return async_setup_rpc_entry(hass, config_entry, async_add_entities)
|
||||
|
||||
return await async_setup_block_entry(hass, config_entry, async_add_entities)
|
||||
return async_setup_block_entry(hass, config_entry, async_add_entities)
|
||||
|
||||
|
||||
async def async_setup_block_entry(
|
||||
@callback
|
||||
def async_setup_block_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
@ -59,7 +60,7 @@ async def async_setup_block_entry(
|
|||
|
||||
relay_blocks.append(block)
|
||||
unique_id = f"{wrapper.mac}-{block.type}_{block.channel}"
|
||||
await async_remove_shelly_entity(hass, "light", unique_id)
|
||||
async_remove_shelly_entity(hass, "light", unique_id)
|
||||
|
||||
if not relay_blocks:
|
||||
return
|
||||
|
@ -67,7 +68,8 @@ async def async_setup_block_entry(
|
|||
async_add_entities(BlockRelaySwitch(wrapper, block) for block in relay_blocks)
|
||||
|
||||
|
||||
async def async_setup_rpc_entry(
|
||||
@callback
|
||||
def async_setup_rpc_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
|
@ -84,7 +86,7 @@ async def async_setup_rpc_entry(
|
|||
|
||||
switch_ids.append(id_)
|
||||
unique_id = f"{wrapper.mac}-switch:{id_}"
|
||||
await async_remove_shelly_entity(hass, "light", unique_id)
|
||||
async_remove_shelly_entity(hass, "light", unique_id)
|
||||
|
||||
if not switch_ids:
|
||||
return
|
||||
|
|
|
@ -30,7 +30,8 @@ from .const import (
|
|||
)
|
||||
|
||||
|
||||
async def async_remove_shelly_entity(
|
||||
@callback
|
||||
def async_remove_shelly_entity(
|
||||
hass: HomeAssistant, domain: str, unique_id: str
|
||||
) -> None:
|
||||
"""Remove a Shelly entity."""
|
||||
|
|
Loading…
Add table
Reference in a new issue