diff --git a/homeassistant/components/moon/sensor.py b/homeassistant/components/moon/sensor.py index b033dccc296..c244f161471 100644 --- a/homeassistant/components/moon/sensor.py +++ b/homeassistant/components/moon/sensor.py @@ -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.""" diff --git a/homeassistant/components/moon/strings.json b/homeassistant/components/moon/strings.json index 76ce886ded8..818460bc13d 100644 --- a/homeassistant/components/moon/strings.json +++ b/homeassistant/components/moon/strings.json @@ -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" + } + } + } } } diff --git a/homeassistant/components/moon/strings.sensor.json b/homeassistant/components/moon/strings.sensor.json deleted file mode 100644 index 3bbff0a776b..00000000000 --- a/homeassistant/components/moon/strings.sensor.json +++ /dev/null @@ -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" - } - } -} diff --git a/homeassistant/components/moon/translations/en.json b/homeassistant/components/moon/translations/en.json index 2f6f73a9982..b1e3ffeb619 100644 --- a/homeassistant/components/moon/translations/en.json +++ b/homeassistant/components/moon/translations/en.json @@ -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.", diff --git a/tests/components/moon/test_sensor.py b/tests/components/moon/test_sensor.py index 6f13c97a3be..e4826fce2e8 100644 --- a/tests/components/moon/test_sensor.py +++ b/tests/components/moon/test_sensor.py @@ -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