diff --git a/homeassistant/components/dsmr/sensor.py b/homeassistant/components/dsmr/sensor.py index 9e05111d284..75a21f6d677 100644 --- a/homeassistant/components/dsmr/sensor.py +++ b/homeassistant/components/dsmr/sensor.py @@ -97,6 +97,9 @@ SENSORS: tuple[DSMRSensorEntityDescription, ...] = ( name="Active tariff", obis_reference=obis_references.ELECTRICITY_ACTIVE_TARIFF, dsmr_versions={"2.2", "4", "5", "5B", "5L"}, + device_class=SensorDeviceClass.ENUM, + options=["low", "normal"], + translation_key="electricity_tariff", icon="mdi:flash", ), DSMRSensorEntityDescription( diff --git a/homeassistant/components/dsmr/strings.json b/homeassistant/components/dsmr/strings.json index cc9cd2ae86a..5db3a8bb863 100644 --- a/homeassistant/components/dsmr/strings.json +++ b/homeassistant/components/dsmr/strings.json @@ -40,6 +40,16 @@ "cannot_communicate": "Failed to communicate" } }, + "entity": { + "sensor": { + "electricity_tariff": { + "state": { + "low": "Low", + "normal": "Normal" + } + } + } + }, "options": { "step": { "init": { diff --git a/homeassistant/components/dsmr/translations/en.json b/homeassistant/components/dsmr/translations/en.json index 6f873729bc8..8d29cdd936f 100644 --- a/homeassistant/components/dsmr/translations/en.json +++ b/homeassistant/components/dsmr/translations/en.json @@ -40,6 +40,16 @@ } } }, + "entity": { + "sensor": { + "electricity_tariff": { + "state": { + "low": "Low", + "normal": "Normal" + } + } + } + }, "options": { "step": { "init": { diff --git a/tests/components/dsmr/test_sensor.py b/tests/components/dsmr/test_sensor.py index e8cf763f98e..81ec3871b64 100644 --- a/tests/components/dsmr/test_sensor.py +++ b/tests/components/dsmr/test_sensor.py @@ -13,6 +13,7 @@ from unittest.mock import DEFAULT, MagicMock from homeassistant import config_entries from homeassistant.components.sensor import ( + ATTR_OPTIONS, ATTR_STATE_CLASS, SensorDeviceClass, SensorStateClass, @@ -116,8 +117,9 @@ async def test_default_setup(hass, dsmr_connection_fixture): # tariff should be translated in human readable and have no unit active_tariff = hass.states.get("sensor.electricity_meter_active_tariff") assert active_tariff.state == "low" - assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None + assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash" + assert active_tariff.attributes.get(ATTR_OPTIONS) == ["low", "normal"] assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "" @@ -215,8 +217,9 @@ async def test_v4_meter(hass, dsmr_connection_fixture): # tariff should be translated in human readable and have no unit active_tariff = hass.states.get("sensor.electricity_meter_active_tariff") assert active_tariff.state == "low" - assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None + assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash" + assert active_tariff.attributes.get(ATTR_OPTIONS) == ["low", "normal"] assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "" @@ -286,8 +289,9 @@ async def test_v5_meter(hass, dsmr_connection_fixture): # tariff should be translated in human readable and have no unit active_tariff = hass.states.get("sensor.electricity_meter_active_tariff") assert active_tariff.state == "low" - assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None + assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash" + assert active_tariff.attributes.get(ATTR_OPTIONS) == ["low", "normal"] assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "" @@ -440,8 +444,9 @@ async def test_belgian_meter(hass, dsmr_connection_fixture): # tariff should be translated in human readable and have no unit active_tariff = hass.states.get("sensor.electricity_meter_active_tariff") assert active_tariff.state == "normal" - assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None + assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash" + assert active_tariff.attributes.get(ATTR_OPTIONS) == ["low", "normal"] assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "" @@ -499,8 +504,9 @@ async def test_belgian_meter_low(hass, dsmr_connection_fixture): # tariff should be translated in human readable and have no unit active_tariff = hass.states.get("sensor.electricity_meter_active_tariff") assert active_tariff.state == "low" - assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None + assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash" + assert active_tariff.attributes.get(ATTR_OPTIONS) == ["low", "normal"] assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""