mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Prefix sma sensor name (#65234)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
27038fda27
commit
496583bca5
@ -84,7 +84,12 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._sensor.name
|
if self._attr_device_info is None or not (
|
||||||
|
name_prefix := self._attr_device_info.get("name")
|
||||||
|
):
|
||||||
|
name_prefix = "SMA"
|
||||||
|
|
||||||
|
return f"{name_prefix} {self._sensor.name}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
|
@ -4,6 +4,6 @@ from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, POWER_WATT
|
|||||||
|
|
||||||
async def test_sensors(hass, init_integration):
|
async def test_sensors(hass, init_integration):
|
||||||
"""Test states of the sensors."""
|
"""Test states of the sensors."""
|
||||||
state = hass.states.get("sensor.grid_power")
|
state = hass.states.get("sensor.sma_device_grid_power")
|
||||||
assert state
|
assert state
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user