Use enum sensor device class in Season (#83301)
parent
303f203c2a
commit
06c8b838b5
|
@ -8,6 +8,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
|
@ -132,8 +133,10 @@ def get_season(
|
|||
class SeasonSensorEntity(SensorEntity):
|
||||
"""Representation of the current season."""
|
||||
|
||||
_attr_device_class = "season__season"
|
||||
_attr_device_class = SensorDeviceClass.ENUM
|
||||
_attr_has_entity_name = True
|
||||
_attr_options = ["spring", "summer", "autumn", "winter"]
|
||||
_attr_translation_key = "season"
|
||||
|
||||
def __init__(self, entry: ConfigEntry, hemisphere: str) -> None:
|
||||
"""Initialize the season."""
|
||||
|
|
|
@ -16,5 +16,17 @@
|
|||
"title": "The Season YAML configuration has been removed",
|
||||
"description": "Configuring Season using YAML has been removed.\n\nYour existing YAML configuration is not used by Home Assistant.\n\nRemove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"season": {
|
||||
"state": {
|
||||
"spring": "Spring",
|
||||
"summer": "Summer",
|
||||
"autumn": "Autumn",
|
||||
"winter": "Winter"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"state": {
|
||||
"season__season": {
|
||||
"spring": "Spring",
|
||||
"summer": "Summer",
|
||||
"autumn": "Autumn",
|
||||
"winter": "Winter"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,18 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"season": {
|
||||
"state": {
|
||||
"autumn": "Autumn",
|
||||
"spring": "Spring",
|
||||
"summer": "Summer",
|
||||
"winter": "Winter"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"removed_yaml": {
|
||||
"description": "Configuring Season using YAML has been removed.\n\nYour existing YAML configuration is not used by Home Assistant.\n\nRemove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue.",
|
||||
|
|
|
@ -15,7 +15,8 @@ from homeassistant.components.season.sensor import (
|
|||
STATE_SUMMER,
|
||||
STATE_WINTER,
|
||||
)
|
||||
from homeassistant.const import CONF_TYPE, STATE_UNKNOWN
|
||||
from homeassistant.components.sensor import ATTR_OPTIONS, SensorDeviceClass
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS, CONF_TYPE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
|
@ -92,11 +93,14 @@ async def test_season_northern_hemisphere(
|
|||
state = hass.states.get("sensor.season")
|
||||
assert state
|
||||
assert state.state == expected
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.ENUM
|
||||
assert state.attributes[ATTR_OPTIONS] == ["spring", "summer", "autumn", "winter"]
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
entry = entity_registry.async_get("sensor.season")
|
||||
assert entry
|
||||
assert entry.unique_id == mock_config_entry.entry_id
|
||||
assert entry.translation_key == "season"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("type,day,expected", SOUTHERN_PARAMETERS, ids=idfn)
|
||||
|
@ -121,11 +125,14 @@ async def test_season_southern_hemisphere(
|
|||
state = hass.states.get("sensor.season")
|
||||
assert state
|
||||
assert state.state == expected
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.ENUM
|
||||
assert state.attributes[ATTR_OPTIONS] == ["spring", "summer", "autumn", "winter"]
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
entry = entity_registry.async_get("sensor.season")
|
||||
assert entry
|
||||
assert entry.unique_id == mock_config_entry.entry_id
|
||||
assert entry.translation_key == "season"
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
assert entry.device_id
|
||||
|
|
Loading…
Reference in New Issue