1 """Support for tracking the moon phases."""
3 from __future__
import annotations
5 from astral
import moon
14 from .const
import DOMAIN
16 STATE_FIRST_QUARTER =
"first_quarter"
17 STATE_FULL_MOON =
"full_moon"
18 STATE_LAST_QUARTER =
"last_quarter"
19 STATE_NEW_MOON =
"new_moon"
20 STATE_WANING_CRESCENT =
"waning_crescent"
21 STATE_WANING_GIBBOUS =
"waning_gibbous"
22 STATE_WAXING_CRESCENT =
"waxing_crescent"
23 STATE_WAXING_GIBBOUS =
"waxing_gibbous"
29 async_add_entities: AddEntitiesCallback,
31 """Set up the platform from config_entry."""
36 """Representation of a Moon sensor."""
38 _attr_has_entity_name =
True
39 _attr_device_class = SensorDeviceClass.ENUM
42 STATE_WAXING_CRESCENT,
48 STATE_WANING_CRESCENT,
50 _attr_translation_key =
"phase"
52 def __init__(self, entry: ConfigEntry) ->
None:
53 """Initialize the moon sensor."""
57 identifiers={(DOMAIN, entry.entry_id)},
58 entry_type=DeviceEntryType.SERVICE,
62 """Get the time and updates the states."""
63 today = dt_util.now().
date()
64 state = moon.phase(today)
66 if state < 0.5
or state > 27.5:
None __init__(self, ConfigEntry entry)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)