Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0dbb410

Browse files
thecodefrenck
authored andcommitted
Fix Shelly missing Gen value for older devices (home-assistant#107294)
1 parent 5ff6284 commit 0dbb410

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

‎homeassistant/components/shelly/config_flow.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from .utils import (
3737
get_block_device_sleep_period,
3838
get_coap_context,
39+
get_device_entry_gen,
3940
get_info_auth,
4041
get_info_gen,
4142
get_model_name,
@@ -322,7 +323,7 @@ async def async_step_reauth_confirm(
322323
except (DeviceConnectionError, InvalidAuthError, FirmwareUnsupported):
323324
return self.async_abort(reason="reauth_unsuccessful")
324325

325-
if self.entry.data.get(CONF_GEN, 1) != 1:
326+
if get_device_entry_gen(self.entry) != 1:
326327
user_input[CONF_USERNAME] = "admin"
327328
try:
328329
await validate_input(self.hass, host, info, user_input)
@@ -335,7 +336,7 @@ async def async_step_reauth_confirm(
335336
await self.hass.config_entries.async_reload(self.entry.entry_id)
336337
return self.async_abort(reason="reauth_successful")
337338

338-
if self.entry.data.get(CONF_GEN, 1) in BLOCK_GENERATIONS:
339+
if get_device_entry_gen(self.entry) in BLOCK_GENERATIONS:
339340
schema = {
340341
vol.Required(CONF_USERNAME): str,
341342
vol.Required(CONF_PASSWORD): str,
@@ -364,7 +365,7 @@ def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlowHandler:
364365
def async_supports_options_flow(cls, config_entry: ConfigEntry) -> bool:
365366
"""Return options flow support for this handler."""
366367
return (
367-
config_entry.data.get(CONF_GEN) in RPC_GENERATIONS
368+
get_device_entry_gen(config_entry) in RPC_GENERATIONS
368369
and not config_entry.data.get(CONF_SLEEP_PERIOD)
369370
and config_entry.data.get("model") != MODEL_WALL_DISPLAY
370371
)

‎homeassistant/components/shelly/coordinator.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
ATTR_GENERATION,
3434
BATTERY_DEVICES_WITH_PERMANENT_CONNECTION,
3535
CONF_BLE_SCANNER_MODE,
36-
CONF_GEN,
3736
CONF_SLEEP_PERIOD,
3837
DATA_CONFIG_ENTRY,
3938
DOMAIN,
@@ -58,7 +57,11 @@
5857
UPDATE_PERIOD_MULTIPLIER,
5958
BLEScannerMode,
6059
)
61-
from .utils import get_rpc_device_wakeup_period, update_device_fw_info
60+
from .utils import (
61+
get_device_entry_gen,
62+
get_rpc_device_wakeup_period,
63+
update_device_fw_info,
64+
)
6265

6366
_DeviceT = TypeVar("_DeviceT", bound="BlockDevice|RpcDevice")
6467

@@ -136,7 +139,7 @@ def async_setup(self) -> None:
136139
manufacturer="Shelly",
137140
model=aioshelly.const.MODEL_NAMES.get(self.model, self.model),
138141
sw_version=self.sw_version,
139-
hw_version=f"gen{self.entry.data[CONF_GEN]} ({self.model})",
142+
hw_version=f"gen{get_device_entry_gen(self.entry)} ({self.model})",
140143
configuration_url=f"http://{self.entry.data[CONF_HOST]}",
141144
)
142145
self.device_id = device_entry.id

‎tests/components/shelly/__init__.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pytest
1313

1414
from homeassistant.components.shelly.const import (
15+
CONF_GEN,
1516
CONF_SLEEP_PERIOD,
1617
DOMAIN,
1718
REST_SENSORS_UPDATE_INTERVAL,
@@ -30,7 +31,7 @@
3031

3132
async def init_integration(
3233
hass: HomeAssistant,
33-
gen: int,
34+
gen: int|None,
3435
model=MODEL_25,
3536
sleep_period=0,
3637
options: dict[str, Any] | None = None,
@@ -41,8 +42,9 @@ async def init_integration(
4142
CONF_HOST: "192.168.1.37",
4243
CONF_SLEEP_PERIOD: sleep_period,
4344
"model": model,
44-
"gen": gen,
4545
}
46+
if gen is not None:
47+
data[CONF_GEN] = gen
4648

4749
entry = MockConfigEntry(
4850
domain=DOMAIN, data=data, unique_id=MOCK_MAC, options=options

‎tests/components/shelly/test_init.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,11 @@ async def test_no_attempt_to_stop_scanner_with_sleepy_devices(
301301
mock_rpc_device.mock_update()
302302
await hass.async_block_till_done()
303303
assert not mock_stop_scanner.call_count
304+
305+
306+
async def test_entry_missing_gen(hass: HomeAssistant, mock_block_device) -> None:
307+
"""Test successful Gen1 device init when gen is missing in entry data."""
308+
entry = await init_integration(hass, None)
309+
310+
assert entry.state is ConfigEntryState.LOADED
311+
assert hass.states.get("switch.test_name_channel_1").state is STATE_ON

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /