1313from homeassistant .core import HomeAssistant , State , callback
1414from homeassistant .exceptions import HomeAssistantError
1515from homeassistant .helpers import entity_registry as er
16+ from homeassistant .helpers .device_registry import DeviceInfo
1617from homeassistant .helpers .entity import Entity , EntityDescription
1718from homeassistant .helpers .entity_platform import AddEntitiesCallback
1819from homeassistant .helpers .entity_registry import RegistryEntry
@@ -368,15 +369,7 @@ def __init__(self, coordinator: ShellyBlockCoordinator, block: Block) -> None:
368369 super ().__init__ (coordinator )
369370 self .block = block
370371 self ._attr_name = get_block_entity_name (coordinator .device , block )
371- self ._attr_device_info = get_block_device_info (
372- coordinator .device ,
373- coordinator .mac ,
374- coordinator .configuration_url ,
375- coordinator .model ,
376- coordinator .model_name ,
377- block ,
378- suggested_area = coordinator .suggested_area ,
379- )
372+ self ._attr_device_info = get_entity_block_device_info (coordinator , block )
380373 self ._attr_unique_id = f"{ coordinator .mac } -{ block .description } "
381374
382375 # pylint: disable-next=hass-missing-super-call
@@ -417,15 +410,7 @@ def __init__(self, coordinator: ShellyRpcCoordinator, key: str) -> None:
417410 """Initialize Shelly entity."""
418411 super ().__init__ (coordinator )
419412 self .key = key
420- self ._attr_device_info = get_rpc_device_info (
421- coordinator .device ,
422- coordinator .mac ,
423- coordinator .configuration_url ,
424- coordinator .model ,
425- coordinator .model_name ,
426- key ,
427- suggested_area = coordinator .suggested_area ,
428- )
413+ self ._attr_device_info = get_entity_rpc_device_info (coordinator , key )
429414 self ._attr_unique_id = f"{ coordinator .mac } -{ key } "
430415 self ._attr_name = get_rpc_entity_name (coordinator .device , key )
431416
@@ -539,14 +524,7 @@ def __init__(
539524 coordinator .device , None , description .name
540525 )
541526 self ._attr_unique_id = f"{ coordinator .mac } -{ attribute } "
542- self ._attr_device_info = get_block_device_info (
543- coordinator .device ,
544- coordinator .mac ,
545- coordinator .configuration_url ,
546- coordinator .model ,
547- coordinator .model_name ,
548- suggested_area = coordinator .suggested_area ,
549- )
527+ self ._attr_device_info = get_entity_block_device_info (coordinator )
550528 self ._last_value = None
551529
552530 @property
@@ -653,15 +631,7 @@ def __init__(
653631 self .block : Block | None = block # type: ignore[assignment]
654632 self .entity_description = description
655633
656- self ._attr_device_info = get_block_device_info (
657- coordinator .device ,
658- coordinator .mac ,
659- coordinator .configuration_url ,
660- coordinator .model ,
661- coordinator .model_name ,
662- block ,
663- suggested_area = coordinator .suggested_area ,
664- )
634+ self ._attr_device_info = get_entity_block_device_info (coordinator , block )
665635
666636 if block is not None :
667637 self ._attr_unique_id = (
@@ -726,18 +696,8 @@ def __init__(
726696 self .attribute = attribute
727697 self .entity_description = description
728698
729- self ._attr_device_info = get_rpc_device_info (
730- coordinator .device ,
731- coordinator .mac ,
732- coordinator .configuration_url ,
733- coordinator .model ,
734- coordinator .model_name ,
735- key ,
736- suggested_area = coordinator .suggested_area ,
737- )
738- self ._attr_unique_id = self ._attr_unique_id = (
739- f"{ coordinator .mac } -{ key } -{ attribute } "
740- )
699+ self ._attr_device_info = get_entity_rpc_device_info (coordinator , key )
700+ self ._attr_unique_id = f"{ coordinator .mac } -{ key } -{ attribute } "
741701 self ._last_value = None
742702
743703 if coordinator .device .initialized :
@@ -763,3 +723,37 @@ def get_entity_class(
763723 return description .entity_class
764724
765725 return sensor_class
726+
727+
728+ def get_entity_block_device_info (
729+ coordinator : ShellyBlockCoordinator ,
730+ block : Block | None = None ,
731+ ) -> DeviceInfo :
732+ """Get device info for block entities."""
733+ return get_block_device_info (
734+ coordinator .device ,
735+ coordinator .mac ,
736+ coordinator .configuration_url ,
737+ coordinator .model ,
738+ coordinator .model_name ,
739+ block ,
740+ suggested_area = coordinator .suggested_area ,
741+ )
742+
743+
744+ def get_entity_rpc_device_info (
745+ coordinator : ShellyRpcCoordinator ,
746+ key : str | None = None ,
747+ emeter_phase : str | None = None ,
748+ ) -> DeviceInfo :
749+ """Get device info for RPC entities."""
750+ return get_rpc_device_info (
751+ coordinator .device ,
752+ coordinator .mac ,
753+ coordinator .configuration_url ,
754+ coordinator .model ,
755+ coordinator .model_name ,
756+ key ,
757+ emeter_phase = emeter_phase ,
758+ suggested_area = coordinator .suggested_area ,
759+ )
0 commit comments