mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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
@ -151,8 +151,7 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
|
|||||||
sleep_period = entry.data.get(CONF_SLEEP_PERIOD)
|
sleep_period = entry.data.get(CONF_SLEEP_PERIOD)
|
||||||
shelly_entry_data = get_entry_data(hass)[entry.entry_id]
|
shelly_entry_data = get_entry_data(hass)[entry.entry_id]
|
||||||
|
|
||||||
@callback
|
async def _async_block_device_setup() -> None:
|
||||||
def _async_block_device_setup() -> None:
|
|
||||||
"""Set up a block based device that is online."""
|
"""Set up a block based device that is online."""
|
||||||
shelly_entry_data.block = ShellyBlockCoordinator(hass, entry, device)
|
shelly_entry_data.block = ShellyBlockCoordinator(hass, entry, device)
|
||||||
shelly_entry_data.block.async_setup()
|
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)
|
shelly_entry_data.rest = ShellyRestCoordinator(hass, device, entry)
|
||||||
platforms = BLOCK_PLATFORMS
|
platforms = BLOCK_PLATFORMS
|
||||||
|
|
||||||
hass.config_entries.async_setup_platforms(entry, platforms)
|
await hass.config_entries.async_forward_entry_setups(entry, platforms)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_device_online(_: Any) -> None:
|
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"]
|
data["model"] = device.settings["device"]["type"]
|
||||||
hass.config_entries.async_update_entry(entry, data=data)
|
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:
|
if sleep_period == 0:
|
||||||
# Not a sleeping device, finish setup
|
# 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:
|
except InvalidAuthError as err:
|
||||||
raise ConfigEntryAuthFailed(repr(err)) from 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:
|
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
|
||||||
shelly_entry_data.device = device
|
shelly_entry_data.device = device
|
||||||
@ -199,7 +198,7 @@ async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> b
|
|||||||
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)
|
||||||
_async_block_device_setup()
|
await _async_block_device_setup()
|
||||||
|
|
||||||
return True
|
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)
|
sleep_period = entry.data.get(CONF_SLEEP_PERIOD)
|
||||||
shelly_entry_data = get_entry_data(hass)[entry.entry_id]
|
shelly_entry_data = get_entry_data(hass)[entry.entry_id]
|
||||||
|
|
||||||
@callback
|
async def _async_rpc_device_setup() -> None:
|
||||||
def _async_rpc_device_setup() -> None:
|
|
||||||
"""Set up a RPC based device that is online."""
|
"""Set up a RPC based device that is online."""
|
||||||
shelly_entry_data.rpc = ShellyRpcCoordinator(hass, entry, device)
|
shelly_entry_data.rpc = ShellyRpcCoordinator(hass, entry, device)
|
||||||
shelly_entry_data.rpc.async_setup()
|
shelly_entry_data.rpc.async_setup()
|
||||||
@ -250,7 +248,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
|
|||||||
)
|
)
|
||||||
platforms = RPC_PLATFORMS
|
platforms = RPC_PLATFORMS
|
||||||
|
|
||||||
hass.config_entries.async_setup_platforms(entry, platforms)
|
await hass.config_entries.async_forward_entry_setups(entry, platforms)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_device_online(_: Any, update_type: UpdateType) -> None:
|
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)
|
data[CONF_SLEEP_PERIOD] = get_rpc_device_sleep_period(device.config)
|
||||||
hass.config_entries.async_update_entry(entry, data=data)
|
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:
|
if sleep_period == 0:
|
||||||
# Not a sleeping device, finish setup
|
# 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:
|
except InvalidAuthError as err:
|
||||||
raise ConfigEntryAuthFailed(repr(err)) from 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:
|
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
|
||||||
shelly_entry_data.device = device
|
shelly_entry_data.device = device
|
||||||
@ -285,7 +283,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ConfigEntry) -> boo
|
|||||||
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)
|
||||||
_async_rpc_device_setup()
|
await _async_rpc_device_setup()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user