mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add fjäråskupan sensor (#54921)
* Add fjäråskupan sensor * Update homeassistant/components/fjaraskupan/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Type the return value of constructor * Update __init__.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
69e413ac1e
commit
4bdeba8631
@ -322,6 +322,7 @@ omit =
|
|||||||
homeassistant/components/fjaraskupan/const.py
|
homeassistant/components/fjaraskupan/const.py
|
||||||
homeassistant/components/fjaraskupan/fan.py
|
homeassistant/components/fjaraskupan/fan.py
|
||||||
homeassistant/components/fjaraskupan/light.py
|
homeassistant/components/fjaraskupan/light.py
|
||||||
|
homeassistant/components/fjaraskupan/sensor.py
|
||||||
homeassistant/components/fleetgo/device_tracker.py
|
homeassistant/components/fleetgo/device_tracker.py
|
||||||
homeassistant/components/flexit/climate.py
|
homeassistant/components/flexit/climate.py
|
||||||
homeassistant/components/flic/binary_sensor.py
|
homeassistant/components/flic/binary_sensor.py
|
||||||
|
@ -23,7 +23,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|||||||
|
|
||||||
from .const import DISPATCH_DETECTION, DOMAIN
|
from .const import DISPATCH_DETECTION, DOMAIN
|
||||||
|
|
||||||
PLATFORMS = ["binary_sensor", "fan", "light"]
|
PLATFORMS = ["binary_sensor", "fan", "light", "sensor"]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
66
homeassistant/components/fjaraskupan/sensor.py
Normal file
66
homeassistant/components/fjaraskupan/sensor.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"""Support for sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from fjaraskupan import Device, State
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import (
|
||||||
|
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
SensorEntity,
|
||||||
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import StateType
|
||||||
|
from homeassistant.helpers.update_coordinator import (
|
||||||
|
CoordinatorEntity,
|
||||||
|
DataUpdateCoordinator,
|
||||||
|
)
|
||||||
|
|
||||||
|
from . import DeviceState, async_setup_entry_platform
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up sensors dynamically through discovery."""
|
||||||
|
|
||||||
|
def _constructor(device_state: DeviceState) -> list[Entity]:
|
||||||
|
return [
|
||||||
|
RssiSensor(
|
||||||
|
device_state.coordinator, device_state.device, device_state.device_info
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
async_setup_entry_platform(hass, config_entry, async_add_entities, _constructor)
|
||||||
|
|
||||||
|
|
||||||
|
class RssiSensor(CoordinatorEntity[State], SensorEntity):
|
||||||
|
"""Sensor device."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: DataUpdateCoordinator[State],
|
||||||
|
device: Device,
|
||||||
|
device_info: DeviceInfo,
|
||||||
|
) -> None:
|
||||||
|
"""Init sensor."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self._attr_unique_id = f"{device.address}-signal-strength"
|
||||||
|
self._attr_device_info = device_info
|
||||||
|
self._attr_name = f"{device_info['name']} Signal Strength"
|
||||||
|
self._attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH
|
||||||
|
self._attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
|
self._attr_unit_of_measurement = SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||||
|
self._attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def native_value(self) -> StateType:
|
||||||
|
"""Return the value reported by the sensor."""
|
||||||
|
if data := self.coordinator.data:
|
||||||
|
return data.rssi
|
||||||
|
return None
|
Loading…
x
Reference in New Issue
Block a user