mirror of
https://github.com/home-assistant/core.git
synced 2025-07-03 03:17:05 +00:00

* Add probe_plus integration * Changes for quality scale * sentence-casing * Update homeassistant/components/probe_plus/config_flow.py Co-authored-by: Erwin Douna <e.douna@gmail.com> * Update homeassistant/components/probe_plus/config_flow.py Co-authored-by: Erwin Douna <e.douna@gmail.com> * Update tests/components/probe_plus/test_config_flow.py Co-authored-by: Erwin Douna <e.douna@gmail.com> * Update tests/components/probe_plus/test_config_flow.py Co-authored-by: Erwin Douna <e.douna@gmail.com> * remove version from configflow * remove address var from async_step_bluetooth_confirm * move timedelta to SCAN_INTERVAL in coordinator * update tests * updates from review * add voltage device class * remove unused logger * remove names * update tests * Update config flow tests * Update unit tests * Reorder successful tests * Update config entry typing * Remove icons * ruff * Update async_add_entities logic Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * sensor platform formatting --------- Co-authored-by: Erwin Douna <e.douna@gmail.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
107 lines
3.7 KiB
Python
107 lines
3.7 KiB
Python
"""Support for Probe Plus BLE sensors."""
|
|
|
|
from collections.abc import Callable
|
|
from dataclasses import dataclass
|
|
|
|
from homeassistant.components.sensor import (
|
|
RestoreSensor,
|
|
SensorDeviceClass,
|
|
SensorEntityDescription,
|
|
SensorStateClass,
|
|
)
|
|
from homeassistant.const import (
|
|
PERCENTAGE,
|
|
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
|
EntityCategory,
|
|
UnitOfElectricPotential,
|
|
UnitOfTemperature,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|
|
|
from .coordinator import ProbePlusConfigEntry, ProbePlusDevice
|
|
from .entity import ProbePlusEntity
|
|
|
|
# Coordinator is used to centralize the data updates
|
|
PARALLEL_UPDATES = 0
|
|
|
|
|
|
@dataclass(kw_only=True, frozen=True)
|
|
class ProbePlusSensorEntityDescription(SensorEntityDescription):
|
|
"""Description for Probe Plus sensor entities."""
|
|
|
|
value_fn: Callable[[ProbePlusDevice], int | float | None]
|
|
|
|
|
|
SENSOR_DESCRIPTIONS: tuple[ProbePlusSensorEntityDescription, ...] = (
|
|
ProbePlusSensorEntityDescription(
|
|
key="probe_temperature",
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
|
value_fn=lambda device: device.device_state.probe_temperature,
|
|
device_class=SensorDeviceClass.TEMPERATURE,
|
|
),
|
|
ProbePlusSensorEntityDescription(
|
|
key="probe_battery",
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
native_unit_of_measurement=PERCENTAGE,
|
|
value_fn=lambda device: device.device_state.probe_battery,
|
|
device_class=SensorDeviceClass.BATTERY,
|
|
),
|
|
ProbePlusSensorEntityDescription(
|
|
key="relay_battery",
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
native_unit_of_measurement=PERCENTAGE,
|
|
value_fn=lambda device: device.device_state.relay_battery,
|
|
device_class=SensorDeviceClass.BATTERY,
|
|
),
|
|
ProbePlusSensorEntityDescription(
|
|
key="probe_rssi",
|
|
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
value_fn=lambda device: device.device_state.probe_rssi,
|
|
entity_registry_enabled_default=False,
|
|
),
|
|
ProbePlusSensorEntityDescription(
|
|
key="relay_voltage",
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
device_class=SensorDeviceClass.VOLTAGE,
|
|
value_fn=lambda device: device.device_state.relay_voltage,
|
|
entity_registry_enabled_default=False,
|
|
),
|
|
ProbePlusSensorEntityDescription(
|
|
key="probe_voltage",
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
device_class=SensorDeviceClass.VOLTAGE,
|
|
value_fn=lambda device: device.device_state.probe_voltage,
|
|
entity_registry_enabled_default=False,
|
|
),
|
|
)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ProbePlusConfigEntry,
|
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
|
) -> None:
|
|
"""Set up the Probe Plus sensors."""
|
|
coordinator = entry.runtime_data
|
|
async_add_entities(ProbeSensor(coordinator, desc) for desc in SENSOR_DESCRIPTIONS)
|
|
|
|
|
|
class ProbeSensor(ProbePlusEntity, RestoreSensor):
|
|
"""Representation of a Probe Plus sensor."""
|
|
|
|
entity_description: ProbePlusSensorEntityDescription
|
|
|
|
@property
|
|
def native_value(self) -> int | float | None:
|
|
"""Return the state of the sensor."""
|
|
return self.entity_description.value_fn(self.device)
|