From 49388670e19d34d630664faf969f9a0dbddd3758 Mon Sep 17 00:00:00 2001 From: Getslow6 <43093176+Getslow6@users.noreply.github.com> Date: Fri, 18 Apr 2025 12:19:49 +0000 Subject: [PATCH 1/4] Change the automatic naming of entities --- custom_components/monitor_docker/button.py | 7 +++++-- custom_components/monitor_docker/helpers.py | 2 +- custom_components/monitor_docker/sensor.py | 8 ++++---- custom_components/monitor_docker/switch.py | 4 +++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/custom_components/monitor_docker/button.py b/custom_components/monitor_docker/button.py index 0f1dc89..16756a6 100644 --- a/custom_components/monitor_docker/button.py +++ b/custom_components/monitor_docker/button.py @@ -183,7 +183,10 @@ def __init__( self._attr_unique_id = ENTITY_ID_FORMAT.format( slugify(f"{self._instance}_{self._cname}_restart") ) - self._attr_name = f"{self._instance} {self._cname} Restart" + + self._attr_has_entity_name = True + self._attr_name = "Restart container" + self.entity_id = f"button.{self._instance}_{self._cname}_restart" self._removed = False @property @@ -192,7 +195,7 @@ def should_poll(self) -> bool: @property def icon(self) -> str: - return "mdi:docker" + return "mdi:restart" @property def extra_state_attributes(self) -> dict: diff --git a/custom_components/monitor_docker/helpers.py b/custom_components/monitor_docker/helpers.py index e68b4a6..35cf43e0 100644 --- a/custom_components/monitor_docker/helpers.py +++ b/custom_components/monitor_docker/helpers.py @@ -1664,7 +1664,7 @@ def __init__( container_info = container.get_info() self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, f"{instance}_container_{cname}")}, - name=cname, + name=cname.capitalize(), manufacturer="Docker", model="Docker Container", entry_type=DeviceEntryType.SERVICE, diff --git a/custom_components/monitor_docker/sensor.py b/custom_components/monitor_docker/sensor.py index 72a0ba4..9b2d67c 100644 --- a/custom_components/monitor_docker/sensor.py +++ b/custom_components/monitor_docker/sensor.py @@ -301,14 +301,14 @@ def __init__( self._attr_unique_id = ENTITY_ID_FORMAT.format( slugify(f"{self._instance}_{self._cname}_allinone") ) - self._attr_name = f"{self._instance} {self._cname} AllInOne".strip() + self._attr_name = "AllInOne" + self.entity_id = f"sensor.{self._instance}_{self._cname}_allinone".strip() else: self._attr_unique_id = ENTITY_ID_FORMAT.format( slugify(f"{self._instance}_{cname}_{self.entity_description.name}") ) - self._attr_name = ( - f"{self._instance} {self._cname} {self.entity_description.name}".strip() - ) + self._attr_name = self.entity_description.name + self.entity_id = f"sensor.{self._instance}_{self._cname}_{self.entity_description.name}".strip() self._state = None self._state_extra = None diff --git a/custom_components/monitor_docker/switch.py b/custom_components/monitor_docker/switch.py index 106737c..f74a28e 100644 --- a/custom_components/monitor_docker/switch.py +++ b/custom_components/monitor_docker/switch.py @@ -182,7 +182,9 @@ def __init__( self._attr_unique_id: str = ENTITY_ID_FORMAT.format( slugify(f"{self._instance}_{self._cname}") ) - self._name = f"{self._instance} {self._cname}" + self._name = self._cname.capitalize() + self._attr_has_entity_name = True + self.entity_id = f"switch.{self._instance}_{self._cname}" self._removed = False @property From a359857827016c443c52fdd3b12936993d139e5a Mon Sep 17 00:00:00 2001 From: Getslow6 <43093176+Getslow6@users.noreply.github.com> Date: Fri, 18 Apr 2025 12:28:40 +0000 Subject: [PATCH 2/4] Ensure no spaces in entity_id --- custom_components/monitor_docker/sensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/monitor_docker/sensor.py b/custom_components/monitor_docker/sensor.py index 9b2d67c..9c0f050 100644 --- a/custom_components/monitor_docker/sensor.py +++ b/custom_components/monitor_docker/sensor.py @@ -302,13 +302,13 @@ def __init__( slugify(f"{self._instance}_{self._cname}_allinone") ) self._attr_name = "AllInOne" - self.entity_id = f"sensor.{self._instance}_{self._cname}_allinone".strip() + self.entity_id = f"sensor.{self._instance}_{self._cname}_allinone".replace(" ", "") else: self._attr_unique_id = ENTITY_ID_FORMAT.format( slugify(f"{self._instance}_{cname}_{self.entity_description.name}") ) self._attr_name = self.entity_description.name - self.entity_id = f"sensor.{self._instance}_{self._cname}_{self.entity_description.name}".strip() + self.entity_id = f"sensor.{self._instance}_{self._cname}_{self.entity_description.name}".replace(" ", "") self._state = None self._state_extra = None From bf324d34f6e8e2dabc241670be19ef8d61503570 Mon Sep 17 00:00:00 2001 From: Getslow6 Date: Fri, 22 Aug 2025 21:52:29 +0200 Subject: [PATCH 3/4] Make the Switch the main entity of a device, resulting in a better friendly name for the entity. --- custom_components/monitor_docker/switch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/monitor_docker/switch.py b/custom_components/monitor_docker/switch.py index f74a28e..0d4d94e 100644 --- a/custom_components/monitor_docker/switch.py +++ b/custom_components/monitor_docker/switch.py @@ -190,7 +190,10 @@ def __init__( @property def name(self) -> str: """Return the name of the sensor.""" - return self._name + # Return None, as this is the main entity for the device. The friendly name + # will then be equal to the device name ('Home-Assistant') instead of a combination + # of the device name and entity name ('Home-Assistant Home-Assistant') + return None @property def should_poll(self) -> bool: From 78cdab1be7d6defd23028de80fb5610ea4cff20b Mon Sep 17 00:00:00 2001 From: Getslow6 Date: Fri, 22 Aug 2025 22:01:01 +0200 Subject: [PATCH 4/4] Better name implementation using attributes --- custom_components/monitor_docker/switch.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/custom_components/monitor_docker/switch.py b/custom_components/monitor_docker/switch.py index 0d4d94e..cdfa888 100644 --- a/custom_components/monitor_docker/switch.py +++ b/custom_components/monitor_docker/switch.py @@ -184,17 +184,11 @@ def __init__( ) self._name = self._cname.capitalize() self._attr_has_entity_name = True + self._attr_name = None + self.entity_id = f"switch.{self._instance}_{self._cname}" self._removed = False - @property - def name(self) -> str: - """Return the name of the sensor.""" - # Return None, as this is the main entity for the device. The friendly name - # will then be equal to the device name ('Home-Assistant') instead of a combination - # of the device name and entity name ('Home-Assistant Home-Assistant') - return None - @property def should_poll(self) -> bool: return False