Skip to content

Commit a89faf2

Browse files
authored
Merge pull request #77 from Monitor-My-Solar/monitormysolarDEV
Monitormysolar dev
2 parents b09baba + edbfd83 commit a89faf2

4 files changed

Lines changed: 41 additions & 18 deletions

File tree

custom_components/monitormysolar/entity.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
class MonitorMySolarEntity(CoordinatorEntity[MonitorMySolar]):
1414
"""Base MonitorMySolar entity."""
1515

16-
_attr_has_entity_name = True
17-
1816
def __init__(
1917
self,
2018
coordinator: MonitorMySolar,
@@ -23,6 +21,11 @@ def __init__(
2321
"""Initialize light."""
2422
super().__init__(coordinator)
2523

24+
# Dynamically set has_entity_name based on number of dongles
25+
# If single dongle, don't use entity name (cleaner display)
26+
# If multiple dongles, use entity name for clarity
27+
self._attr_has_entity_name = len(coordinator._dongle_ids) > 1
28+
2629
# If this attribute is not set in a subclass, default to True
2730
if not hasattr(self, '_attr_entity_registry_enabled_default'):
2831
self._attr_entity_registry_enabled_default = True
@@ -75,7 +78,7 @@ def get_device_info(self, dongle_id: str, manufacturer: str) -> dict:
7578
# Note: Home Assistant expects exactly these field names
7679
device_info = {
7780
"identifiers": {(DOMAIN, dongle_id)},
78-
"name": f"{dongle_id}",
81+
"name": dongle_id,
7982
}
8083

8184
# Default model and manufacturer values

custom_components/monitormysolar/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"issue_tracker": "https://github.com/Monitor-My-Solar/monitormysolar",
1111
"loggers": [],
1212
"requirements": [],
13-
"version": "3.0.1"
13+
"version": "3.0.3"
1414
}
1515

custom_components/monitormysolar/sensor.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,13 @@ def __init__(self, sensor_info, hass, entry, bank_name, dongle_id):
141141
@property
142142
def name(self):
143143
"""Return the name of the sensor."""
144-
# When has_entity_name is True, just return the entity name
145-
# Home Assistant will combine it with the device name
146-
return self._name
144+
# If single dongle (has_entity_name is False), return just the name
145+
# If multiple dongles (has_entity_name is True), return entity name only
146+
if self._attr_has_entity_name:
147+
return self._name
148+
else:
149+
# For single dongle, return a clean name without device prefix
150+
return self._name
147151

148152
@property
149153
def unique_id(self):
@@ -275,9 +279,13 @@ def __init__(self, sensor_info, hass, entry, bank_name, dongle_id):
275279
@property
276280
def name(self):
277281
"""Return the name of the sensor."""
278-
# When has_entity_name is True, just return the entity name
279-
# Home Assistant will combine it with the device name
280-
return self._name
282+
# If single dongle (has_entity_name is False), return just the name
283+
# If multiple dongles (has_entity_name is True), return entity name only
284+
if self._attr_has_entity_name:
285+
return self._name
286+
else:
287+
# For single dongle, return a clean name without device prefix
288+
return self._name
281289

282290
@property
283291
def unique_id(self):
@@ -348,9 +356,13 @@ def __init__(self, sensor_info, hass, entry, bank_name, dongle_id):
348356
@property
349357
def name(self):
350358
"""Return the name of the sensor."""
351-
# When has_entity_name is True, just return the entity name
352-
# Home Assistant will combine it with the device name
353-
return self._name
359+
# If single dongle (has_entity_name is False), return just the name
360+
# If multiple dongles (has_entity_name is True), return entity name only
361+
if self._attr_has_entity_name:
362+
return self._name
363+
else:
364+
# For single dongle, return a clean name without device prefix
365+
return self._name
354366

355367
@property
356368
def unique_id(self):
@@ -499,9 +511,13 @@ def __init__(self, sensor_info, hass, entry, bank_name, dongle_id):
499511
@property
500512
def name(self):
501513
"""Return the name of the sensor."""
502-
# When has_entity_name is True, just return the entity name
503-
# Home Assistant will combine it with the device name
504-
return self._name
514+
# If single dongle (has_entity_name is False), return just the name
515+
# If multiple dongles (has_entity_name is True), return entity name only
516+
if self._attr_has_entity_name:
517+
return self._name
518+
else:
519+
# For single dongle, return a clean name without device prefix
520+
return self._name
505521

506522
@property
507523
def unique_id(self):

custom_components/monitormysolar/update.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class DongleFirmwareUpdate(MonitorMySolarEntity, UpdateEntity):
7575

7676
_attr_supported_features = UpdateEntityFeature.RELEASE_NOTES | UpdateEntityFeature.INSTALL | UpdateEntityFeature.PROGRESS
7777
_attr_device_class = UpdateDeviceClass.FIRMWARE
78-
_attr_has_entity_name = True
7978

8079
def __init__(
8180
self,
@@ -105,7 +104,12 @@ def device_info(self):
105104
@property
106105
def name(self):
107106
"""Return the name of the entity."""
108-
return f"{self._dongle_id} Firmware"
107+
if self._attr_has_entity_name:
108+
# Multiple dongles - return just "Firmware"
109+
return "Firmware"
110+
else:
111+
# Single dongle - return full name
112+
return "Firmware Update"
109113

110114
@property
111115
def unique_id(self):

0 commit comments

Comments
 (0)