Don't override icon in sensor group when device class is set (#87304)

This commit is contained in:
Franck Nijhof 2023-02-03 16:38:05 +01:00 committed by GitHub
parent 61734f04b8
commit 1b4f4edce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -244,7 +244,6 @@ class SensorGroup(GroupEntity, SensorEntity):
_attr_available = False
_attr_should_poll = False
_attr_icon = "mdi:calculator"
def __init__(
self,
@ -352,6 +351,16 @@ class SensorGroup(GroupEntity, SensorEntity):
return self._attr_device_class
return self.calc_device_class
@property
def icon(self) -> str | None:
"""Return the icon.
Only override the icon if the device class is not set.
"""
if not self.device_class:
return "mdi:calculator"
return None
@property
def state_class(self) -> SensorStateClass | str | None:
"""Return state class."""

View File

@ -24,6 +24,7 @@ from homeassistant.components.sensor import (
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_ENTITY_ID,
ATTR_ICON,
ATTR_UNIT_OF_MEASUREMENT,
SERVICE_RELOAD,
STATE_UNAVAILABLE,
@ -99,6 +100,7 @@ async def test_sensors(
for key, value in attributes.items():
assert state.attributes.get(key) == value
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.VOLUME
assert state.attributes.get(ATTR_ICON) is None
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "L"