Use enum sensor device class in Season (#83301)

pull/83310/head
Franck Nijhof 2022-12-05 13:48:32 +01:00 committed by GitHub
parent 303f203c2a
commit 06c8b838b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 12 deletions

View File

@ -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."""

View File

@ -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"
}
}
}
}
}

View File

@ -1,10 +0,0 @@
{
"state": {
"season__season": {
"spring": "Spring",
"summer": "Summer",
"autumn": "Autumn",
"winter": "Winter"
}
}
}

View File

@ -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.",

View File

@ -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