mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Clean up Shelly async methods that are not awaiting (#72026)
This commit is contained in:
parent
c0da97b038
commit
0d94324d58
@ -182,7 +182,7 @@ async def async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> bo
|
|||||||
data["model"] = device.settings["device"]["type"]
|
data["model"] = device.settings["device"]["type"]
|
||||||
hass.config_entries.async_update_entry(entry, data=data)
|
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:
|
if sleep_period == 0:
|
||||||
# Not a sleeping device, finish setup
|
# 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:
|
except OSError as err:
|
||||||
raise ConfigEntryNotReady(str(err) or "Error during device setup") from 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:
|
elif sleep_period is None or device_entry is None:
|
||||||
# Need to get sleep info or first time sleeping device setup, wait for device
|
# 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
|
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:
|
else:
|
||||||
# Restore sensors for sleeping device
|
# Restore sensors for sleeping device
|
||||||
LOGGER.debug("Setting up offline block device %s", entry.title)
|
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
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_block_device_setup(
|
@callback
|
||||||
|
def async_block_device_setup(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, device: BlockDevice
|
hass: HomeAssistant, entry: ConfigEntry, device: BlockDevice
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a block based device that is online."""
|
"""Set up a block based device that is online."""
|
||||||
|
@ -235,12 +235,12 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up sensors for device."""
|
"""Set up sensors for device."""
|
||||||
if get_device_entry_gen(config_entry) == 2:
|
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
|
hass, config_entry, async_add_entities, RPC_SENSORS, RpcBinarySensor
|
||||||
)
|
)
|
||||||
|
|
||||||
if config_entry.data[CONF_SLEEP_PERIOD]:
|
if config_entry.data[CONF_SLEEP_PERIOD]:
|
||||||
await async_setup_entry_attribute_entities(
|
async_setup_entry_attribute_entities(
|
||||||
hass,
|
hass,
|
||||||
config_entry,
|
config_entry,
|
||||||
async_add_entities,
|
async_add_entities,
|
||||||
@ -249,7 +249,7 @@ async def async_setup_entry(
|
|||||||
_build_block_description,
|
_build_block_description,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await async_setup_entry_attribute_entities(
|
async_setup_entry_attribute_entities(
|
||||||
hass,
|
hass,
|
||||||
config_entry,
|
config_entry,
|
||||||
async_add_entities,
|
async_add_entities,
|
||||||
@ -257,7 +257,7 @@ async def async_setup_entry(
|
|||||||
BlockBinarySensor,
|
BlockBinarySensor,
|
||||||
_build_block_description,
|
_build_block_description,
|
||||||
)
|
)
|
||||||
await async_setup_entry_rest(
|
async_setup_entry_rest(
|
||||||
hass,
|
hass,
|
||||||
config_entry,
|
config_entry,
|
||||||
async_add_entities,
|
async_add_entities,
|
||||||
|
@ -50,14 +50,13 @@ async def async_setup_entry(
|
|||||||
][BLOCK]
|
][BLOCK]
|
||||||
|
|
||||||
if wrapper.device.initialized:
|
if wrapper.device.initialized:
|
||||||
await async_setup_climate_entities(async_add_entities, wrapper)
|
async_setup_climate_entities(async_add_entities, wrapper)
|
||||||
else:
|
else:
|
||||||
await async_restore_climate_entities(
|
async_restore_climate_entities(hass, config_entry, async_add_entities, wrapper)
|
||||||
hass, config_entry, async_add_entities, wrapper
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_climate_entities(
|
@callback
|
||||||
|
def async_setup_climate_entities(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
wrapper: BlockDeviceWrapper,
|
wrapper: BlockDeviceWrapper,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -79,7 +78,8 @@ async def async_setup_climate_entities(
|
|||||||
async_add_entities([BlockSleepingClimate(wrapper, sensor_block, device_block)])
|
async_add_entities([BlockSleepingClimate(wrapper, sensor_block, device_block)])
|
||||||
|
|
||||||
|
|
||||||
async def async_restore_climate_entities(
|
@callback
|
||||||
|
def async_restore_climate_entities(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
@ -28,12 +28,13 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up switches for device."""
|
"""Set up switches for device."""
|
||||||
if get_device_entry_gen(config_entry) == 2:
|
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,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
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_add_entities(BlockShellyCover(wrapper, block) for block in blocks)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_rpc_entry(
|
@callback
|
||||||
|
def async_setup_rpc_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
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,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
@ -62,11 +63,11 @@ async def async_setup_entry_attribute_entities(
|
|||||||
][BLOCK]
|
][BLOCK]
|
||||||
|
|
||||||
if wrapper.device.initialized:
|
if wrapper.device.initialized:
|
||||||
await async_setup_block_attribute_entities(
|
async_setup_block_attribute_entities(
|
||||||
hass, async_add_entities, wrapper, sensors, sensor_class
|
hass, async_add_entities, wrapper, sensors, sensor_class
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await async_restore_block_attribute_entities(
|
async_restore_block_attribute_entities(
|
||||||
hass,
|
hass,
|
||||||
config_entry,
|
config_entry,
|
||||||
async_add_entities,
|
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,
|
hass: HomeAssistant,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
wrapper: BlockDeviceWrapper,
|
wrapper: BlockDeviceWrapper,
|
||||||
@ -105,7 +107,7 @@ async def async_setup_block_attribute_entities(
|
|||||||
):
|
):
|
||||||
domain = sensor_class.__module__.split(".")[-1]
|
domain = sensor_class.__module__.split(".")[-1]
|
||||||
unique_id = f"{wrapper.mac}-{block.description}-{sensor_id}"
|
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:
|
else:
|
||||||
blocks.append((block, sensor_id, description))
|
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,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
@ -158,7 +161,8 @@ async def async_restore_block_attribute_entities(
|
|||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry_rpc(
|
@callback
|
||||||
|
def async_setup_entry_rpc(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
@ -192,7 +196,7 @@ async def async_setup_entry_rpc(
|
|||||||
):
|
):
|
||||||
domain = sensor_class.__module__.split(".")[-1]
|
domain = sensor_class.__module__.split(".")[-1]
|
||||||
unique_id = f"{wrapper.mac}-{key}-{sensor_id}"
|
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:
|
else:
|
||||||
if description.use_polling_wrapper:
|
if description.use_polling_wrapper:
|
||||||
entities.append(
|
entities.append(
|
||||||
@ -207,7 +211,8 @@ async def async_setup_entry_rpc(
|
|||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry_rest(
|
@callback
|
||||||
|
def async_setup_entry_rest(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
@ -65,12 +65,13 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up lights for device."""
|
"""Set up lights for device."""
|
||||||
if get_device_entry_gen(config_entry) == 2:
|
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,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
@ -92,7 +93,7 @@ async def async_setup_block_entry(
|
|||||||
blocks.append(block)
|
blocks.append(block)
|
||||||
assert wrapper.device.shelly
|
assert wrapper.device.shelly
|
||||||
unique_id = f"{wrapper.mac}-{block.type}_{block.channel}"
|
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:
|
if not blocks:
|
||||||
return
|
return
|
||||||
@ -100,7 +101,8 @@ async def async_setup_block_entry(
|
|||||||
async_add_entities(BlockShellyLight(wrapper, block) for block in blocks)
|
async_add_entities(BlockShellyLight(wrapper, block) for block in blocks)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_rpc_entry(
|
@callback
|
||||||
|
def async_setup_rpc_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
@ -116,7 +118,7 @@ async def async_setup_rpc_entry(
|
|||||||
|
|
||||||
switch_ids.append(id_)
|
switch_ids.append(id_)
|
||||||
unique_id = f"{wrapper.mac}-switch:{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:
|
if not switch_ids:
|
||||||
return
|
return
|
||||||
|
@ -81,7 +81,7 @@ async def async_setup_entry(
|
|||||||
return
|
return
|
||||||
|
|
||||||
if config_entry.data[CONF_SLEEP_PERIOD]:
|
if config_entry.data[CONF_SLEEP_PERIOD]:
|
||||||
await async_setup_entry_attribute_entities(
|
async_setup_entry_attribute_entities(
|
||||||
hass,
|
hass,
|
||||||
config_entry,
|
config_entry,
|
||||||
async_add_entities,
|
async_add_entities,
|
||||||
|
@ -394,12 +394,12 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up sensors for device."""
|
"""Set up sensors for device."""
|
||||||
if get_device_entry_gen(config_entry) == 2:
|
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
|
hass, config_entry, async_add_entities, RPC_SENSORS, RpcSensor
|
||||||
)
|
)
|
||||||
|
|
||||||
if config_entry.data[CONF_SLEEP_PERIOD]:
|
if config_entry.data[CONF_SLEEP_PERIOD]:
|
||||||
await async_setup_entry_attribute_entities(
|
async_setup_entry_attribute_entities(
|
||||||
hass,
|
hass,
|
||||||
config_entry,
|
config_entry,
|
||||||
async_add_entities,
|
async_add_entities,
|
||||||
@ -408,7 +408,7 @@ async def async_setup_entry(
|
|||||||
_build_block_description,
|
_build_block_description,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await async_setup_entry_attribute_entities(
|
async_setup_entry_attribute_entities(
|
||||||
hass,
|
hass,
|
||||||
config_entry,
|
config_entry,
|
||||||
async_add_entities,
|
async_add_entities,
|
||||||
@ -416,7 +416,7 @@ async def async_setup_entry(
|
|||||||
BlockSensor,
|
BlockSensor,
|
||||||
_build_block_description,
|
_build_block_description,
|
||||||
)
|
)
|
||||||
await async_setup_entry_rest(
|
async_setup_entry_rest(
|
||||||
hass, config_entry, async_add_entities, REST_SENSORS, RestSensor
|
hass, config_entry, async_add_entities, REST_SENSORS, RestSensor
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,12 +29,13 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up switches for device."""
|
"""Set up switches for device."""
|
||||||
if get_device_entry_gen(config_entry) == 2:
|
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,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
@ -59,7 +60,7 @@ async def async_setup_block_entry(
|
|||||||
|
|
||||||
relay_blocks.append(block)
|
relay_blocks.append(block)
|
||||||
unique_id = f"{wrapper.mac}-{block.type}_{block.channel}"
|
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:
|
if not relay_blocks:
|
||||||
return
|
return
|
||||||
@ -67,7 +68,8 @@ async def async_setup_block_entry(
|
|||||||
async_add_entities(BlockRelaySwitch(wrapper, block) for block in relay_blocks)
|
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,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
@ -84,7 +86,7 @@ async def async_setup_rpc_entry(
|
|||||||
|
|
||||||
switch_ids.append(id_)
|
switch_ids.append(id_)
|
||||||
unique_id = f"{wrapper.mac}-switch:{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:
|
if not switch_ids:
|
||||||
return
|
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
|
hass: HomeAssistant, domain: str, unique_id: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Remove a Shelly entity."""
|
"""Remove a Shelly entity."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user