Fix Shelly device shutdown (#120881)

This commit is contained in:
Shay Levy 2024-07-01 20:06:56 +03:00 committed by Franck Nijhof
parent 3a0e85beb8
commit a9740faeda
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
5 changed files with 21 additions and 10 deletions

View File

@ -174,10 +174,13 @@ async def _async_setup_block_entry(
await device.initialize() await device.initialize()
if not device.firmware_supported: if not device.firmware_supported:
async_create_issue_unsupported_firmware(hass, entry) async_create_issue_unsupported_firmware(hass, entry)
await device.shutdown()
raise ConfigEntryNotReady raise ConfigEntryNotReady
except (DeviceConnectionError, MacAddressMismatchError) as err: except (DeviceConnectionError, MacAddressMismatchError) as err:
await device.shutdown()
raise ConfigEntryNotReady(repr(err)) from err raise ConfigEntryNotReady(repr(err)) from err
except InvalidAuthError as err: except InvalidAuthError as err:
await device.shutdown()
raise ConfigEntryAuthFailed(repr(err)) from err raise ConfigEntryAuthFailed(repr(err)) from err
runtime_data.block = ShellyBlockCoordinator(hass, entry, device) runtime_data.block = ShellyBlockCoordinator(hass, entry, device)
@ -247,10 +250,13 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ShellyConfigEntry)
await device.initialize() await device.initialize()
if not device.firmware_supported: if not device.firmware_supported:
async_create_issue_unsupported_firmware(hass, entry) async_create_issue_unsupported_firmware(hass, entry)
await device.shutdown()
raise ConfigEntryNotReady raise ConfigEntryNotReady
except (DeviceConnectionError, MacAddressMismatchError) as err: except (DeviceConnectionError, MacAddressMismatchError) as err:
await device.shutdown()
raise ConfigEntryNotReady(repr(err)) from err raise ConfigEntryNotReady(repr(err)) from err
except InvalidAuthError as err: except InvalidAuthError as err:
await device.shutdown()
raise ConfigEntryAuthFailed(repr(err)) from err raise ConfigEntryAuthFailed(repr(err)) from err
runtime_data.rpc = ShellyRpcCoordinator(hass, entry, device) runtime_data.rpc = ShellyRpcCoordinator(hass, entry, device)

View File

@ -102,10 +102,11 @@ async def validate_input(
ws_context, ws_context,
options, options,
) )
await rpc_device.initialize() try:
await rpc_device.shutdown() await rpc_device.initialize()
sleep_period = get_rpc_device_wakeup_period(rpc_device.status)
sleep_period = get_rpc_device_wakeup_period(rpc_device.status) finally:
await rpc_device.shutdown()
return { return {
"title": rpc_device.name, "title": rpc_device.name,
@ -121,11 +122,15 @@ async def validate_input(
coap_context, coap_context,
options, options,
) )
await block_device.initialize() try:
await block_device.shutdown() await block_device.initialize()
sleep_period = get_block_device_sleep_period(block_device.settings)
finally:
await block_device.shutdown()
return { return {
"title": block_device.name, "title": block_device.name,
CONF_SLEEP_PERIOD: get_block_device_sleep_period(block_device.settings), CONF_SLEEP_PERIOD: sleep_period,
"model": block_device.model, "model": block_device.model,
CONF_GEN: gen, CONF_GEN: gen,
} }

View File

@ -9,7 +9,7 @@
"iot_class": "local_push", "iot_class": "local_push",
"loggers": ["aioshelly"], "loggers": ["aioshelly"],
"quality_scale": "platinum", "quality_scale": "platinum",
"requirements": ["aioshelly==10.0.1"], "requirements": ["aioshelly==11.0.0"],
"zeroconf": [ "zeroconf": [
{ {
"type": "_http._tcp.local.", "type": "_http._tcp.local.",

View File

@ -362,7 +362,7 @@ aioruuvigateway==0.1.0
aiosenz==1.0.0 aiosenz==1.0.0
# homeassistant.components.shelly # homeassistant.components.shelly
aioshelly==10.0.1 aioshelly==11.0.0
# homeassistant.components.skybell # homeassistant.components.skybell
aioskybell==22.7.0 aioskybell==22.7.0

View File

@ -335,7 +335,7 @@ aioruuvigateway==0.1.0
aiosenz==1.0.0 aiosenz==1.0.0
# homeassistant.components.shelly # homeassistant.components.shelly
aioshelly==10.0.1 aioshelly==11.0.0
# homeassistant.components.skybell # homeassistant.components.skybell
aioskybell==22.7.0 aioskybell==22.7.0