2021-02-06 07:05:39 +00:00
|
|
|
"""Support for Aurora Forecast sensor."""
|
2024-03-08 13:51:32 +00:00
|
|
|
|
2024-01-17 11:11:34 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-02-28 22:47:29 +00:00
|
|
|
from homeassistant.components.sensor import SensorEntity, SensorStateClass
|
2021-02-06 07:05:39 +00:00
|
|
|
from homeassistant.const import PERCENTAGE
|
2022-01-03 18:18:00 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-02-06 07:05:39 +00:00
|
|
|
|
2024-05-12 19:54:32 +00:00
|
|
|
from . import AuroraConfigEntry
|
2023-06-26 16:24:14 +00:00
|
|
|
from .entity import AuroraEntity
|
2021-02-06 07:05:39 +00:00
|
|
|
|
|
|
|
|
2022-01-03 18:18:00 +00:00
|
|
|
async def async_setup_entry(
|
2024-05-12 19:54:32 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: AuroraConfigEntry,
|
2024-05-15 07:27:19 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2022-01-03 18:18:00 +00:00
|
|
|
) -> None:
|
2021-02-06 07:05:39 +00:00
|
|
|
"""Set up the sensor platform."""
|
|
|
|
|
2024-05-15 07:27:19 +00:00
|
|
|
async_add_entities(
|
2024-05-12 19:54:32 +00:00
|
|
|
[
|
|
|
|
AuroraSensor(
|
|
|
|
coordinator=entry.runtime_data,
|
|
|
|
translation_key="visibility",
|
|
|
|
)
|
|
|
|
]
|
2021-02-06 07:05:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-03-22 19:05:13 +00:00
|
|
|
class AuroraSensor(AuroraEntity, SensorEntity):
|
2021-02-06 07:05:39 +00:00
|
|
|
"""Implementation of an aurora sensor."""
|
|
|
|
|
2021-08-11 08:45:05 +00:00
|
|
|
_attr_native_unit_of_measurement = PERCENTAGE
|
2023-02-28 22:47:29 +00:00
|
|
|
_attr_state_class = SensorStateClass.MEASUREMENT
|
2021-07-08 13:06:00 +00:00
|
|
|
|
2021-02-06 07:05:39 +00:00
|
|
|
@property
|
2024-01-17 11:11:34 +00:00
|
|
|
def native_value(self) -> int:
|
2021-02-06 07:05:39 +00:00
|
|
|
"""Return % chance the aurora is visible."""
|
|
|
|
return self.coordinator.data
|