Files
core/homeassistant/components/opensky/sensor.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2.0 KiB
Python
Raw Normal View History

2019-04-03 17:40:03 +02:00
"""Sensor for the Open Sky Network."""
2022-01-03 19:10:57 +01:00
from __future__ import annotations
from homeassistant.components.sensor import SensorEntity, SensorStateClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
2023-08-11 10:11:13 +02:00
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
2022-01-03 19:10:57 +01:00
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
2017-04-20 01:56:20 -04:00
from .const import DOMAIN, MANUFACTURER
from .coordinator import OpenSkyDataUpdateCoordinator
2023-07-25 20:46:04 +02:00
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Initialize the entries."""
coordinator = hass.data[DOMAIN][entry.entry_id]
2023-07-25 20:46:04 +02:00
async_add_entities(
2019-07-31 12:25:30 -07:00
[
2018-08-24 16:37:30 +02:00
OpenSkySensor(
coordinator,
entry,
2018-07-31 20:45:18 +01:00
)
],
2019-07-31 12:25:30 -07:00
)
2017-04-20 01:56:20 -04:00
class OpenSkySensor(CoordinatorEntity[OpenSkyDataUpdateCoordinator], SensorEntity):
2017-04-20 01:56:20 -04:00
"""Open Sky Network Sensor."""
_attr_attribution = (
"Information provided by the OpenSky Network (https://opensky-network.org)"
)
_attr_has_entity_name = True
_attr_name = None
2024-03-02 00:56:34 +01:00
_attr_translation_key = "flights"
_attr_native_unit_of_measurement = "flights"
_attr_state_class = SensorStateClass.MEASUREMENT
2023-05-24 12:48:55 +02:00
def __init__(
self,
coordinator: OpenSkyDataUpdateCoordinator,
config_entry: ConfigEntry,
2023-05-24 12:48:55 +02:00
) -> None:
2017-04-20 01:56:20 -04:00
"""Initialize the sensor."""
super().__init__(coordinator)
self._attr_unique_id = f"{config_entry.entry_id}_opensky"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{coordinator.config_entry.entry_id}")},
manufacturer=MANUFACTURER,
name=config_entry.title,
entry_type=DeviceEntryType.SERVICE,
)
2017-04-20 01:56:20 -04:00
@property
2023-05-28 02:58:04 +02:00
def native_value(self) -> int:
2017-04-20 01:56:20 -04:00
"""Return the state of the sensor."""
return self.coordinator.data