Use enum sensor device class in Moon (#83108)
* Use enum sensor device class in Moon * Adjust testspull/83180/head
parent
b40923a4cd
commit
58f2fc8610
|
@ -6,6 +6,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
|
||||
|
@ -27,8 +28,8 @@ STATE_LAST_QUARTER = "last_quarter"
|
|||
STATE_NEW_MOON = "new_moon"
|
||||
STATE_WANING_CRESCENT = "waning_crescent"
|
||||
STATE_WANING_GIBBOUS = "waning_gibbous"
|
||||
STATE_WAXING_GIBBOUS = "waxing_gibbous"
|
||||
STATE_WAXING_CRESCENT = "waxing_crescent"
|
||||
STATE_WAXING_GIBBOUS = "waxing_gibbous"
|
||||
|
||||
MOON_ICONS = {
|
||||
STATE_FIRST_QUARTER: "mdi:moon-first-quarter",
|
||||
|
@ -83,9 +84,20 @@ async def async_setup_entry(
|
|||
class MoonSensorEntity(SensorEntity):
|
||||
"""Representation of a Moon sensor."""
|
||||
|
||||
_attr_device_class = "moon__phase"
|
||||
_attr_has_entity_name = True
|
||||
_attr_name = "Phase"
|
||||
_attr_device_class = SensorDeviceClass.ENUM
|
||||
_attr_options = [
|
||||
STATE_FIRST_QUARTER,
|
||||
STATE_FULL_MOON,
|
||||
STATE_LAST_QUARTER,
|
||||
STATE_NEW_MOON,
|
||||
STATE_WANING_CRESCENT,
|
||||
STATE_WANING_GIBBOUS,
|
||||
STATE_WAXING_CRESCENT,
|
||||
STATE_WAXING_GIBBOUS,
|
||||
]
|
||||
_attr_translation_key = "phase"
|
||||
|
||||
def __init__(self, entry: ConfigEntry) -> None:
|
||||
"""Initialize the moon sensor."""
|
||||
|
|
|
@ -15,5 +15,21 @@
|
|||
"title": "The Moon YAML configuration has been removed",
|
||||
"description": "Configuring Moon 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": {
|
||||
"phase": {
|
||||
"state": {
|
||||
"first_quarter": "First quarter",
|
||||
"full_moon": "Full moon",
|
||||
"last_quarter": "Last quarter",
|
||||
"new_moon": "New moon",
|
||||
"waning_crescent": "Waning crescent",
|
||||
"waning_gibbous": "Waning gibbous",
|
||||
"waxing_crescent": "Waxing crescent",
|
||||
"waxing_gibbous": "Waxing gibbous"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"state": {
|
||||
"moon__phase": {
|
||||
"new_moon": "New moon",
|
||||
"waxing_crescent": "Waxing crescent",
|
||||
"first_quarter": "First quarter",
|
||||
"waxing_gibbous": "Waxing gibbous",
|
||||
"full_moon": "Full moon",
|
||||
"waning_gibbous": "Waning gibbous",
|
||||
"last_quarter": "Last quarter",
|
||||
"waning_crescent": "Waning crescent"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,6 +9,22 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"phase": {
|
||||
"state": {
|
||||
"first_quarter": "First quarter",
|
||||
"full_moon": "Full moon",
|
||||
"last_quarter": "Last quarter",
|
||||
"new_moon": "New moon",
|
||||
"waning_crescent": "Waning crescent",
|
||||
"waning_gibbous": "Waning gibbous",
|
||||
"waxing_crescent": "Waxing crescent",
|
||||
"waxing_gibbous": "Waxing gibbous"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"removed_yaml": {
|
||||
"description": "Configuring Moon 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.",
|
||||
|
|
|
@ -16,7 +16,8 @@ from homeassistant.components.moon.sensor import (
|
|||
STATE_WAXING_CRESCENT,
|
||||
STATE_WAXING_GIBBOUS,
|
||||
)
|
||||
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_ICON
|
||||
from homeassistant.components.sensor import ATTR_OPTIONS, SensorDeviceClass
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_FRIENDLY_NAME, ATTR_ICON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
|
@ -57,11 +58,23 @@ async def test_moon_day(
|
|||
assert state.state == native_value
|
||||
assert state.attributes[ATTR_ICON] == icon
|
||||
assert state.attributes[ATTR_FRIENDLY_NAME] == "Moon Phase"
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.ENUM
|
||||
assert state.attributes[ATTR_OPTIONS] == [
|
||||
STATE_FIRST_QUARTER,
|
||||
STATE_FULL_MOON,
|
||||
STATE_LAST_QUARTER,
|
||||
STATE_NEW_MOON,
|
||||
STATE_WANING_CRESCENT,
|
||||
STATE_WANING_GIBBOUS,
|
||||
STATE_WAXING_CRESCENT,
|
||||
STATE_WAXING_GIBBOUS,
|
||||
]
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
entry = entity_registry.async_get("sensor.moon_phase")
|
||||
assert entry
|
||||
assert entry.unique_id == mock_config_entry.entry_id
|
||||
assert entry.translation_key == "phase"
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
assert entry.device_id
|
||||
|
|
Loading…
Reference in New Issue