Prefix sma sensor name (#65234)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
René Klomp 2022-02-19 20:27:06 +01:00 committed by GitHub
parent 27038fda27
commit 496583bca5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -84,7 +84,12 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
@property
def name(self) -> str:
"""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
def native_value(self) -> StateType:

View file

@ -4,6 +4,6 @@ from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, POWER_WATT
async def test_sensors(hass, init_integration):
"""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.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == POWER_WATT