mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Align CONF_ in Shelly integration (#140202)
* Allign CONST_ in Shelly integration * apply review comment
This commit is contained in:
parent
befcd63221
commit
8a51644d1d
@ -16,7 +16,13 @@ from aioshelly.rpc_device import RpcDevice, bluetooth_mac_from_primary_mac
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.bluetooth import async_remove_scanner
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MODEL,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import (
|
||||
@ -159,7 +165,7 @@ async def _async_setup_block_entry(
|
||||
# Following code block will force the right value for affected devices
|
||||
if (
|
||||
sleep_period == BLOCK_WRONG_SLEEP_PERIOD
|
||||
and entry.data["model"] in MODELS_WITH_WRONG_SLEEP_PERIOD
|
||||
and entry.data[CONF_MODEL] in MODELS_WITH_WRONG_SLEEP_PERIOD
|
||||
):
|
||||
LOGGER.warning(
|
||||
"Updating stored sleep period for %s: from %s to %s",
|
||||
|
@ -31,6 +31,7 @@ from homeassistant.config_entries import (
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MAC,
|
||||
CONF_MODEL,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
@ -116,7 +117,9 @@ async def validate_input(
|
||||
return {
|
||||
"title": rpc_device.name,
|
||||
CONF_SLEEP_PERIOD: sleep_period,
|
||||
"model": rpc_device.xmod_info.get("p") or rpc_device.shelly.get("model"),
|
||||
CONF_MODEL: (
|
||||
rpc_device.xmod_info.get("p") or rpc_device.shelly.get(CONF_MODEL)
|
||||
),
|
||||
CONF_GEN: gen,
|
||||
}
|
||||
|
||||
@ -136,7 +139,7 @@ async def validate_input(
|
||||
return {
|
||||
"title": block_device.name,
|
||||
CONF_SLEEP_PERIOD: sleep_period,
|
||||
"model": block_device.model,
|
||||
CONF_MODEL: block_device.model,
|
||||
CONF_GEN: gen,
|
||||
}
|
||||
|
||||
@ -191,14 +194,14 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
if device_info["model"]:
|
||||
if device_info[CONF_MODEL]:
|
||||
return self.async_create_entry(
|
||||
title=device_info["title"],
|
||||
data={
|
||||
CONF_HOST: user_input[CONF_HOST],
|
||||
CONF_PORT: user_input[CONF_PORT],
|
||||
CONF_SLEEP_PERIOD: device_info[CONF_SLEEP_PERIOD],
|
||||
"model": device_info["model"],
|
||||
CONF_MODEL: device_info[CONF_MODEL],
|
||||
CONF_GEN: device_info[CONF_GEN],
|
||||
},
|
||||
)
|
||||
@ -230,7 +233,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
if device_info["model"]:
|
||||
if device_info[CONF_MODEL]:
|
||||
return self.async_create_entry(
|
||||
title=device_info["title"],
|
||||
data={
|
||||
@ -238,7 +241,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
CONF_HOST: self.host,
|
||||
CONF_PORT: self.port,
|
||||
CONF_SLEEP_PERIOD: device_info[CONF_SLEEP_PERIOD],
|
||||
"model": device_info["model"],
|
||||
CONF_MODEL: device_info[CONF_MODEL],
|
||||
CONF_GEN: device_info[CONF_GEN],
|
||||
},
|
||||
)
|
||||
@ -336,7 +339,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle discovery confirm."""
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
if not self.device_info["model"]:
|
||||
if not self.device_info[CONF_MODEL]:
|
||||
errors["base"] = "firmware_not_fully_provisioned"
|
||||
model = "Shelly"
|
||||
else:
|
||||
@ -345,9 +348,9 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_create_entry(
|
||||
title=self.device_info["title"],
|
||||
data={
|
||||
"host": self.host,
|
||||
CONF_HOST: self.host,
|
||||
CONF_SLEEP_PERIOD: self.device_info[CONF_SLEEP_PERIOD],
|
||||
"model": self.device_info["model"],
|
||||
CONF_MODEL: self.device_info[CONF_MODEL],
|
||||
CONF_GEN: self.device_info[CONF_GEN],
|
||||
},
|
||||
)
|
||||
@ -356,8 +359,8 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_show_form(
|
||||
step_id="confirm_discovery",
|
||||
description_placeholders={
|
||||
"model": model,
|
||||
"host": self.host,
|
||||
CONF_MODEL: model,
|
||||
CONF_HOST: self.host,
|
||||
},
|
||||
errors=errors,
|
||||
)
|
||||
@ -466,7 +469,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return (
|
||||
get_device_entry_gen(config_entry) in RPC_GENERATIONS
|
||||
and not config_entry.data.get(CONF_SLEEP_PERIOD)
|
||||
and config_entry.data.get("model") != MODEL_WALL_DISPLAY
|
||||
and config_entry.data.get(CONF_MODEL) != MODEL_WALL_DISPLAY
|
||||
)
|
||||
|
||||
|
||||
|
@ -26,6 +26,7 @@ from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_ID,
|
||||
CONF_HOST,
|
||||
CONF_MODEL,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
Platform,
|
||||
)
|
||||
@ -139,7 +140,7 @@ class ShellyCoordinatorBase[_DeviceT: BlockDevice | RpcDevice](
|
||||
@cached_property
|
||||
def model(self) -> str:
|
||||
"""Model of the device."""
|
||||
return cast(str, self.config_entry.data["model"])
|
||||
return cast(str, self.config_entry.data[CONF_MODEL])
|
||||
|
||||
@cached_property
|
||||
def mac(self) -> str:
|
||||
|
@ -6,7 +6,13 @@ from typing import Any
|
||||
|
||||
from homeassistant.components.bluetooth import async_scanner_by_source
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import (
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_SW_VERSION,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import ShellyConfigEntry
|
||||
@ -30,9 +36,9 @@ async def async_get_config_entry_diagnostics(
|
||||
block_coordinator = shelly_entry_data.block
|
||||
assert block_coordinator
|
||||
device_info = {
|
||||
"name": block_coordinator.name,
|
||||
"model": block_coordinator.model,
|
||||
"sw_version": block_coordinator.sw_version,
|
||||
ATTR_NAME: block_coordinator.name,
|
||||
ATTR_MODEL: block_coordinator.model,
|
||||
ATTR_SW_VERSION: block_coordinator.sw_version,
|
||||
}
|
||||
if block_coordinator.device.initialized:
|
||||
device_settings = {
|
||||
@ -65,9 +71,9 @@ async def async_get_config_entry_diagnostics(
|
||||
rpc_coordinator = shelly_entry_data.rpc
|
||||
assert rpc_coordinator
|
||||
device_info = {
|
||||
"name": rpc_coordinator.name,
|
||||
"model": rpc_coordinator.model,
|
||||
"sw_version": rpc_coordinator.sw_version,
|
||||
ATTR_NAME: rpc_coordinator.name,
|
||||
ATTR_MODEL: rpc_coordinator.model,
|
||||
ATTR_SW_VERSION: rpc_coordinator.sw_version,
|
||||
}
|
||||
if rpc_coordinator.device.initialized:
|
||||
device_settings = {
|
||||
|
@ -28,7 +28,12 @@ from yarl import URL
|
||||
from homeassistant.components import network
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PORT, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MODEL,
|
||||
CONF_PORT,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.helpers import (
|
||||
device_registry as dr,
|
||||
@ -322,7 +327,7 @@ def get_info_gen(info: dict[str, Any]) -> int:
|
||||
def get_model_name(info: dict[str, Any]) -> str:
|
||||
"""Return the device model name."""
|
||||
if get_info_gen(info) in RPC_GENERATIONS:
|
||||
return cast(str, MODEL_NAMES.get(info["model"], info["model"]))
|
||||
return cast(str, MODEL_NAMES.get(info[CONF_MODEL], info[CONF_MODEL]))
|
||||
|
||||
return cast(str, MODEL_NAMES.get(info["type"], info["type"]))
|
||||
|
||||
@ -514,7 +519,7 @@ def async_create_issue_unsupported_firmware(
|
||||
translation_key="unsupported_firmware",
|
||||
translation_placeholders={
|
||||
"device_name": entry.title,
|
||||
"ip_address": entry.data["host"],
|
||||
"ip_address": entry.data[CONF_HOST],
|
||||
},
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user