|
19 | 19 | from .const import (CIRCUITS_ENERGY_CONSUMED, CIRCUITS_ENERGY_PRODUCED, |
20 | 20 | CIRCUITS_POWER, COORDINATOR, CURRENT_RUN_CONFIG, DOMAIN, |
21 | 21 | DSM_GRID_STATE, DSM_STATE, MAIN_RELAY_STATE, |
22 | | - STATUS_SOFTWARE_VER, STORAGE_BATTERY_PERCENTAGE) |
| 22 | + STATUS_SOFTWARE_VER, STORAGE_BATTERY_PERCENTAGE, |
| 23 | + USE_DEVICE_PREFIX) |
23 | 24 | from .coordinator import SpanPanelCoordinator |
24 | 25 | from .options import BATTERY_ENABLE, INVERTER_ENABLE |
25 | 26 | from .span_panel import SpanPanel |
@@ -258,11 +259,22 @@ def __init__( |
258 | 259 | """Initialize Span Panel Sensor base entity.""" |
259 | 260 | super().__init__(data_coordinator, context=description) |
260 | 261 | self.entity_description = description |
261 | | - self._attr_name = f"{description.name}" |
| 262 | + device_info = panel_to_device_info(span_panel) |
| 263 | + self._attr_device_info = device_info |
| 264 | + base_name = f"{description.name}" |
| 265 | + |
| 266 | + if (data_coordinator.config_entry is not None and |
| 267 | + data_coordinator.config_entry.options.get(USE_DEVICE_PREFIX, False) and |
| 268 | + device_info is not None and |
| 269 | + isinstance(device_info, dict) and |
| 270 | + "name" in device_info): |
| 271 | + self._attr_name = f"{device_info['name']} {base_name}" |
| 272 | + else: |
| 273 | + self._attr_name = base_name |
| 274 | + |
262 | 275 | self._attr_unique_id = ( |
263 | 276 | f"span_{span_panel.status.serial_number}_{description.key}" |
264 | 277 | ) |
265 | | - self._attr_device_info = panel_to_device_info(span_panel) |
266 | 278 |
|
267 | 279 | _LOGGER.debug("CREATE SENSOR SPAN [%s]", self._attr_name) |
268 | 280 |
|
@@ -298,9 +310,15 @@ def __init__( |
298 | 310 | span_panel: SpanPanel, |
299 | 311 | ) -> None: |
300 | 312 | """Initialize Span Panel Circuit entity.""" |
301 | | - super().__init__(coordinator, description, span_panel) |
| 313 | + # Create a new description with modified name including circuit name |
| 314 | + circuit_description = SpanPanelCircuitsSensorEntityDescription( |
| 315 | + **{ |
| 316 | + **vars(description), |
| 317 | + "name": f"{name} {description.name}" |
| 318 | + } |
| 319 | + ) |
| 320 | + super().__init__(coordinator, circuit_description, span_panel) |
302 | 321 | self.id = circuit_id |
303 | | - self._attr_name = f"{name} {description.name}" |
304 | 322 | self._attr_unique_id = ( |
305 | 323 | f"span_{span_panel.status.serial_number}_{circuit_id}_{description.key}" |
306 | 324 | ) |
|
0 commit comments