Add configuration URL and model details to Shelly sub device info (#149404)

This commit is contained in:
Shay Levy 2025-07-25 14:26:32 +03:00 committed by GitHub
parent 6920dec352
commit 123cce6d96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 57 additions and 2 deletions

View File

@ -237,12 +237,18 @@ class ShellyButton(ShellyBaseButton):
self._attr_device_info = get_block_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
suggested_area=coordinator.suggested_area,
)
else:
self._attr_device_info = get_rpc_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
suggested_area=coordinator.suggested_area,
)
self._attr_device_info = DeviceInfo(

View File

@ -213,6 +213,9 @@ class BlockSleepingClimate(
self._attr_device_info = get_block_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
sensor_block,
suggested_area=coordinator.suggested_area,
)

View File

@ -145,11 +145,21 @@ class ShellyCoordinatorBase[_DeviceT: BlockDevice | RpcDevice](
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._handle_ha_stop)
)
@cached_property
def configuration_url(self) -> str:
"""Return the configuration URL for the device."""
return f"http://{get_host(self.config_entry.data[CONF_HOST])}:{get_http_port(self.config_entry.data)}"
@cached_property
def model(self) -> str:
"""Model of the device."""
return cast(str, self.config_entry.data[CONF_MODEL])
@cached_property
def model_name(self) -> str | None:
"""Model name of the device."""
return get_shelly_model_name(self.model, self.sleep_period, self.device)
@cached_property
def mac(self) -> str:
"""Mac address of the device."""
@ -175,11 +185,11 @@ class ShellyCoordinatorBase[_DeviceT: BlockDevice | RpcDevice](
connections={(CONNECTION_NETWORK_MAC, self.mac)},
identifiers={(DOMAIN, self.mac)},
manufacturer="Shelly",
model=get_shelly_model_name(self.model, self.sleep_period, self.device),
model=self.model_name,
model_id=self.model,
sw_version=self.sw_version,
hw_version=f"gen{get_device_entry_gen(self.config_entry)}",
configuration_url=f"http://{get_host(self.config_entry.data[CONF_HOST])}:{get_http_port(self.config_entry.data)}",
configuration_url=self.configuration_url,
)
# We want to use the main device area as the suggested area for sub-devices.
if (area_id := device_entry.area_id) is not None:

View File

@ -371,6 +371,9 @@ class ShellyBlockEntity(CoordinatorEntity[ShellyBlockCoordinator]):
self._attr_device_info = get_block_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
block,
suggested_area=coordinator.suggested_area,
)
@ -417,6 +420,9 @@ class ShellyRpcEntity(CoordinatorEntity[ShellyRpcCoordinator]):
self._attr_device_info = get_rpc_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
key,
suggested_area=coordinator.suggested_area,
)
@ -536,6 +542,9 @@ class ShellyRestAttributeEntity(CoordinatorEntity[ShellyBlockCoordinator]):
self._attr_device_info = get_block_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
suggested_area=coordinator.suggested_area,
)
self._last_value = None
@ -647,6 +656,9 @@ class ShellySleepingBlockAttributeEntity(ShellyBlockAttributeEntity):
self._attr_device_info = get_block_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
block,
suggested_area=coordinator.suggested_area,
)
@ -717,6 +729,9 @@ class ShellySleepingRpcAttributeEntity(ShellyRpcAttributeEntity):
self._attr_device_info = get_rpc_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
key,
suggested_area=coordinator.suggested_area,
)

View File

@ -209,6 +209,9 @@ class ShellyRpcEvent(CoordinatorEntity[ShellyRpcCoordinator], EventEntity):
self._attr_device_info = get_rpc_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
key,
suggested_area=coordinator.suggested_area,
)

View File

@ -141,6 +141,9 @@ class RpcEmeterPhaseSensor(RpcSensor):
self._attr_device_info = get_rpc_device_info(
coordinator.device,
coordinator.mac,
coordinator.configuration_url,
coordinator.model,
coordinator.model_name,
key,
emeter_phase=description.emeter_phase,
suggested_area=coordinator.suggested_area,

View File

@ -749,6 +749,9 @@ async def get_rpc_scripts_event_types(
def get_rpc_device_info(
device: RpcDevice,
mac: str,
configuration_url: str,
model: str,
model_name: str | None = None,
key: str | None = None,
emeter_phase: str | None = None,
suggested_area: str | None = None,
@ -771,8 +774,11 @@ def get_rpc_device_info(
identifiers={(DOMAIN, f"{mac}-{key}-{emeter_phase.lower()}")},
name=get_rpc_sub_device_name(device, key, emeter_phase),
manufacturer="Shelly",
model=model_name,
model_id=model,
suggested_area=suggested_area,
via_device=(DOMAIN, mac),
configuration_url=configuration_url,
)
if (
@ -786,8 +792,11 @@ def get_rpc_device_info(
identifiers={(DOMAIN, f"{mac}-{key}")},
name=get_rpc_sub_device_name(device, key),
manufacturer="Shelly",
model=model_name,
model_id=model,
suggested_area=suggested_area,
via_device=(DOMAIN, mac),
configuration_url=configuration_url,
)
@ -810,6 +819,9 @@ def get_blu_trv_device_info(
def get_block_device_info(
device: BlockDevice,
mac: str,
configuration_url: str,
model: str,
model_name: str | None = None,
block: Block | None = None,
suggested_area: str | None = None,
) -> DeviceInfo:
@ -826,8 +838,11 @@ def get_block_device_info(
identifiers={(DOMAIN, f"{mac}-{block.description}")},
name=get_block_sub_device_name(device, block),
manufacturer="Shelly",
model=model_name,
model_id=model,
suggested_area=suggested_area,
via_device=(DOMAIN, mac),
configuration_url=configuration_url,
)