From 8da969b767b26de02d7b958285f9fbe3a8c77b38 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 17 Nov 2022 12:39:51 -0600 Subject: [PATCH] Disable BLE options flow for sleepy shelly devices (#82283) --- .../components/shelly/config_flow.py | 4 +++- tests/components/shelly/test_config_flow.py | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index d02fe9556bf..9bf4a6126b0 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -341,7 +341,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): cls, config_entry: config_entries.ConfigEntry ) -> bool: """Return options flow support for this handler.""" - return config_entry.data.get("gen") == 2 + return config_entry.data.get("gen") == 2 and not config_entry.data.get( + CONF_SLEEP_PERIOD + ) class OptionsFlowHandler(config_entries.OptionsFlow): diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index fa53f8d3467..29f2804054f 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -1,4 +1,6 @@ """Test the Shelly config flow.""" +from __future__ import annotations + from unittest.mock import AsyncMock, Mock, patch from aioshelly.exceptions import ( @@ -927,6 +929,27 @@ async def test_options_flow_enabled_gen_2(hass, mock_rpc_device, hass_ws_client) await hass.config_entries.async_unload(entry.entry_id) +async def test_options_flow_disabled_sleepy_gen_2( + hass, mock_rpc_device, hass_ws_client +): + """Test options are disabled for sleepy gen2 devices.""" + await async_setup_component(hass, "config", {}) + entry = await init_integration(hass, 2, sleep_period=10) + + ws_client = await hass_ws_client(hass) + + await ws_client.send_json( + { + "id": 5, + "type": "config_entries/get", + "domain": "shelly", + } + ) + response = await ws_client.receive_json() + assert response["result"][0]["supports_options"] is False + await hass.config_entries.async_unload(entry.entry_id) + + async def test_options_flow_ble(hass, mock_rpc_device): """Test setting ble options for gen2 devices.""" entry = await init_integration(hass, 2)