From 496583bca576485e946711f9c1ed9095b99fddc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Klomp?= Date: Sat, 19 Feb 2022 20:27:06 +0100 Subject: [PATCH] Prefix sma sensor name (#65234) Co-authored-by: Franck Nijhof --- homeassistant/components/sma/sensor.py | 7 ++++++- tests/components/sma/test_sensor.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/sma/sensor.py b/homeassistant/components/sma/sensor.py index 0d90d89ce98..b06ec499a24 100644 --- a/homeassistant/components/sma/sensor.py +++ b/homeassistant/components/sma/sensor.py @@ -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: diff --git a/tests/components/sma/test_sensor.py b/tests/components/sma/test_sensor.py index 58fafe930c7..9e4149b0720 100644 --- a/tests/components/sma/test_sensor.py +++ b/tests/components/sma/test_sensor.py @@ -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