Get Shelly RPC device gen
from config entry data (#107019)
Use gen from config entry data
This commit is contained in:
parent
ce5455fefc
commit
8c9875c3cc
4 changed files with 16 additions and 11 deletions
|
@ -25,6 +25,7 @@ from homeassistant.helpers.selector import SelectSelector, SelectSelectorConfig
|
|||
|
||||
from .const import (
|
||||
CONF_BLE_SCANNER_MODE,
|
||||
CONF_GEN,
|
||||
CONF_SLEEP_PERIOD,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
|
@ -84,7 +85,7 @@ async def validate_input(
|
|||
"title": rpc_device.name,
|
||||
CONF_SLEEP_PERIOD: sleep_period,
|
||||
"model": rpc_device.shelly.get("model"),
|
||||
"gen": gen,
|
||||
CONF_GEN: gen,
|
||||
}
|
||||
|
||||
# Gen1
|
||||
|
@ -99,7 +100,7 @@ async def validate_input(
|
|||
"title": block_device.name,
|
||||
CONF_SLEEP_PERIOD: get_block_device_sleep_period(block_device.settings),
|
||||
"model": block_device.model,
|
||||
"gen": gen,
|
||||
CONF_GEN: gen,
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,7 +154,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
**user_input,
|
||||
CONF_SLEEP_PERIOD: device_info[CONF_SLEEP_PERIOD],
|
||||
"model": device_info["model"],
|
||||
"gen": device_info["gen"],
|
||||
CONF_GEN: device_info[CONF_GEN],
|
||||
},
|
||||
)
|
||||
errors["base"] = "firmware_not_fully_provisioned"
|
||||
|
@ -190,7 +191,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
CONF_HOST: self.host,
|
||||
CONF_SLEEP_PERIOD: device_info[CONF_SLEEP_PERIOD],
|
||||
"model": device_info["model"],
|
||||
"gen": device_info["gen"],
|
||||
CONF_GEN: device_info[CONF_GEN],
|
||||
},
|
||||
)
|
||||
errors["base"] = "firmware_not_fully_provisioned"
|
||||
|
@ -288,7 +289,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
"host": self.host,
|
||||
CONF_SLEEP_PERIOD: self.device_info[CONF_SLEEP_PERIOD],
|
||||
"model": self.device_info["model"],
|
||||
"gen": self.device_info["gen"],
|
||||
CONF_GEN: self.device_info[CONF_GEN],
|
||||
},
|
||||
)
|
||||
self._set_confirm_only()
|
||||
|
@ -321,7 +322,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
except (DeviceConnectionError, InvalidAuthError, FirmwareUnsupported):
|
||||
return self.async_abort(reason="reauth_unsuccessful")
|
||||
|
||||
if self.entry.data.get("gen", 1) != 1:
|
||||
if self.entry.data.get(CONF_GEN, 1) != 1:
|
||||
user_input[CONF_USERNAME] = "admin"
|
||||
try:
|
||||
await validate_input(self.hass, host, info, user_input)
|
||||
|
@ -334,7 +335,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
await self.hass.config_entries.async_reload(self.entry.entry_id)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
if self.entry.data.get("gen", 1) in BLOCK_GENERATIONS:
|
||||
if self.entry.data.get(CONF_GEN, 1) in BLOCK_GENERATIONS:
|
||||
schema = {
|
||||
vol.Required(CONF_USERNAME): str,
|
||||
vol.Required(CONF_PASSWORD): str,
|
||||
|
@ -363,7 +364,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
def async_supports_options_flow(cls, config_entry: ConfigEntry) -> bool:
|
||||
"""Return options flow support for this handler."""
|
||||
return (
|
||||
config_entry.data.get("gen") in RPC_GENERATIONS
|
||||
config_entry.data.get(CONF_GEN) in RPC_GENERATIONS
|
||||
and not config_entry.data.get(CONF_SLEEP_PERIOD)
|
||||
and config_entry.data.get("model") != MODEL_WALL_DISPLAY
|
||||
)
|
||||
|
|
|
@ -214,3 +214,5 @@ DEVICES_WITHOUT_FIRMWARE_CHANGELOG = (
|
|||
MODEL_MOTION_2,
|
||||
MODEL_VALVE,
|
||||
)
|
||||
|
||||
CONF_GEN = "gen"
|
||||
|
|
|
@ -33,6 +33,7 @@ from .const import (
|
|||
ATTR_GENERATION,
|
||||
BATTERY_DEVICES_WITH_PERMANENT_CONNECTION,
|
||||
CONF_BLE_SCANNER_MODE,
|
||||
CONF_GEN,
|
||||
CONF_SLEEP_PERIOD,
|
||||
DATA_CONFIG_ENTRY,
|
||||
DOMAIN,
|
||||
|
@ -135,7 +136,7 @@ class ShellyCoordinatorBase(DataUpdateCoordinator[None], Generic[_DeviceT]):
|
|||
manufacturer="Shelly",
|
||||
model=aioshelly.const.MODEL_NAMES.get(self.model, self.model),
|
||||
sw_version=self.sw_version,
|
||||
hw_version=f"gen{self.device.gen} ({self.model})",
|
||||
hw_version=f"gen{self.entry.data[CONF_GEN]} ({self.model})",
|
||||
configuration_url=f"http://{self.entry.data[CONF_HOST]}",
|
||||
)
|
||||
self.device_id = device_entry.id
|
||||
|
|
|
@ -34,6 +34,7 @@ from homeassistant.util.dt import utcnow
|
|||
from .const import (
|
||||
BASIC_INPUTS_EVENTS_TYPES,
|
||||
CONF_COAP_PORT,
|
||||
CONF_GEN,
|
||||
DEFAULT_COAP_PORT,
|
||||
DEVICES_WITHOUT_FIRMWARE_CHANGELOG,
|
||||
DOMAIN,
|
||||
|
@ -281,7 +282,7 @@ def get_info_auth(info: dict[str, Any]) -> bool:
|
|||
|
||||
def get_info_gen(info: dict[str, Any]) -> int:
|
||||
"""Return the device generation from shelly info."""
|
||||
return int(info.get("gen", 1))
|
||||
return int(info.get(CONF_GEN, 1))
|
||||
|
||||
|
||||
def get_model_name(info: dict[str, Any]) -> str:
|
||||
|
@ -325,7 +326,7 @@ def get_rpc_entity_name(
|
|||
|
||||
def get_device_entry_gen(entry: ConfigEntry) -> int:
|
||||
"""Return the device generation from config entry."""
|
||||
return entry.data.get("gen", 1)
|
||||
return entry.data.get(CONF_GEN, 1)
|
||||
|
||||
|
||||
def get_rpc_key_instances(keys_dict: dict[str, Any], key: str) -> list[str]:
|
||||
|
|
Loading…
Add table
Reference in a new issue