Migrate shelly to use async_forward_entry_setups (#86554)
Replaces deprecated async_setup_platforms with async_forward_entry_setups
This commit is contained in:
parent
09891ead8d
commit
099b844dce
1 changed files with 10 additions and 12 deletions
|
@ -151,8 +151,7 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
|
|||
sleep_period = entry.data.get(CONF_SLEEP_PERIOD)
|
||||
shelly_entry_data = get_entry_data(hass)[entry.entry_id]
|
||||
|
||||
@callback
|
||||
def _async_block_device_setup() -> None:
|
||||
async def _async_block_device_setup() -> None:
|
||||
"""Set up a block based device that is online."""
|
||||
shelly_entry_data.block = ShellyBlockCoordinator(hass, entry, device)
|
||||
shelly_entry_data.block.async_setup()
|
||||
|
@ -163,7 +162,7 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
|
|||
shelly_entry_data.rest = ShellyRestCoordinator(hass, device, entry)
|
||||
platforms = BLOCK_PLATFORMS
|
||||
|
||||
hass.config_entries.async_setup_platforms(entry, platforms)
|
||||
await hass.config_entries.async_forward_entry_setups(entry, platforms)
|
||||
|
||||
@callback
|
||||
def _async_device_online(_: Any) -> None:
|
||||
|
@ -176,7 +175,7 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
|
|||
data["model"] = device.settings["device"]["type"]
|
||||
hass.config_entries.async_update_entry(entry, data=data)
|
||||
|
||||
_async_block_device_setup()
|
||||
hass.async_create_task(_async_block_device_setup())
|
||||
|
||||
if sleep_period == 0:
|
||||
# Not a sleeping device, finish setup
|
||||
|
@ -188,7 +187,7 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
|
|||
except InvalidAuthError as err:
|
||||
raise ConfigEntryAuthFailed(repr(err)) from err
|
||||
|
||||
_async_block_device_setup()
|
||||
await _async_block_device_setup()
|
||||
elif sleep_period is None or device_entry is None:
|
||||
# Need to get sleep info or first time sleeping device setup, wait for device
|
||||
shelly_entry_data.device = device
|
||||
|
@ -199,7 +198,7 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
|
|||
else:
|
||||
# Restore sensors for sleeping device
|
||||
LOGGER.debug("Setting up offline block device %s", entry.title)
|
||||
_async_block_device_setup()
|
||||
await _async_block_device_setup()
|
||||
|
||||
return True
|
||||
|
||||
|
@ -236,8 +235,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
|
|||
sleep_period = entry.data.get(CONF_SLEEP_PERIOD)
|
||||
shelly_entry_data = get_entry_data(hass)[entry.entry_id]
|
||||
|
||||
@callback
|
||||
def _async_rpc_device_setup() -> None:
|
||||
async def _async_rpc_device_setup() -> None:
|
||||
"""Set up a RPC based device that is online."""
|
||||
shelly_entry_data.rpc = ShellyRpcCoordinator(hass, entry, device)
|
||||
shelly_entry_data.rpc.async_setup()
|
||||
|
@ -250,7 +248,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
|
|||
)
|
||||
platforms = RPC_PLATFORMS
|
||||
|
||||
hass.config_entries.async_setup_platforms(entry, platforms)
|
||||
await hass.config_entries.async_forward_entry_setups(entry, platforms)
|
||||
|
||||
@callback
|
||||
def _async_device_online(_: Any, update_type: UpdateType) -> None:
|
||||
|
@ -262,7 +260,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
|
|||
data[CONF_SLEEP_PERIOD] = get_rpc_device_sleep_period(device.config)
|
||||
hass.config_entries.async_update_entry(entry, data=data)
|
||||
|
||||
_async_rpc_device_setup()
|
||||
hass.async_create_task(_async_rpc_device_setup())
|
||||
|
||||
if sleep_period == 0:
|
||||
# Not a sleeping device, finish setup
|
||||
|
@ -274,7 +272,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
|
|||
except InvalidAuthError as err:
|
||||
raise ConfigEntryAuthFailed(repr(err)) from err
|
||||
|
||||
_async_rpc_device_setup()
|
||||
await _async_rpc_device_setup()
|
||||
elif sleep_period is None or device_entry is None:
|
||||
# Need to get sleep info or first time sleeping device setup, wait for device
|
||||
shelly_entry_data.device = device
|
||||
|
@ -285,7 +283,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
|
|||
else:
|
||||
# Restore sensors for sleeping device
|
||||
LOGGER.debug("Setting up offline block device %s", entry.title)
|
||||
_async_rpc_device_setup()
|
||||
await _async_rpc_device_setup()
|
||||
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue