Add OSO Energy binary sensors (#117174)
parent
05d0174e07
commit
1c2cda5033
|
@ -977,6 +977,7 @@ omit =
|
|||
homeassistant/components/oru/*
|
||||
homeassistant/components/orvibo/switch.py
|
||||
homeassistant/components/osoenergy/__init__.py
|
||||
homeassistant/components/osoenergy/binary_sensor.py
|
||||
homeassistant/components/osoenergy/sensor.py
|
||||
homeassistant/components/osoenergy/water_heater.py
|
||||
homeassistant/components/osramlightify/light.py
|
||||
|
|
|
@ -23,10 +23,12 @@ from .const import DOMAIN
|
|||
|
||||
MANUFACTURER = "OSO Energy"
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.SENSOR,
|
||||
Platform.WATER_HEATER,
|
||||
]
|
||||
PLATFORM_LOOKUP = {
|
||||
Platform.BINARY_SENSOR: "binary_sensor",
|
||||
Platform.SENSOR: "sensor",
|
||||
Platform.WATER_HEATER: "water_heater",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
"""Support for OSO Energy binary sensors."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
|
||||
from apyosoenergyapi import OSOEnergy
|
||||
from apyosoenergyapi.helper.const import OSOEnergyBinarySensorData
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import OSOEnergyEntity
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class OSOEnergyBinarySensorEntityDescription(BinarySensorEntityDescription):
|
||||
"""Class describing OSO Energy heater binary sensor entities."""
|
||||
|
||||
value_fn: Callable[[OSOEnergy], bool]
|
||||
|
||||
|
||||
SENSOR_TYPES: dict[str, OSOEnergyBinarySensorEntityDescription] = {
|
||||
"power_save": OSOEnergyBinarySensorEntityDescription(
|
||||
key="power_save",
|
||||
translation_key="power_save",
|
||||
value_fn=lambda entity_data: entity_data.state,
|
||||
),
|
||||
"extra_energy": OSOEnergyBinarySensorEntityDescription(
|
||||
key="extra_energy",
|
||||
translation_key="extra_energy",
|
||||
value_fn=lambda entity_data: entity_data.state,
|
||||
),
|
||||
"heater_state": OSOEnergyBinarySensorEntityDescription(
|
||||
key="heating",
|
||||
translation_key="heating",
|
||||
value_fn=lambda entity_data: entity_data.state,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up OSO Energy binary sensor."""
|
||||
osoenergy: OSOEnergy = hass.data[DOMAIN][entry.entry_id]
|
||||
entities = [
|
||||
OSOEnergyBinarySensor(osoenergy, sensor_type, dev)
|
||||
for dev in osoenergy.session.device_list.get("binary_sensor", [])
|
||||
if (sensor_type := SENSOR_TYPES.get(dev.osoEnergyType.lower()))
|
||||
]
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class OSOEnergyBinarySensor(
|
||||
OSOEnergyEntity[OSOEnergyBinarySensorData], BinarySensorEntity
|
||||
):
|
||||
"""OSO Energy Sensor Entity."""
|
||||
|
||||
entity_description: OSOEnergyBinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
instance: OSOEnergy,
|
||||
description: OSOEnergyBinarySensorEntityDescription,
|
||||
entity_data: OSOEnergyBinarySensorData,
|
||||
) -> None:
|
||||
"""Set up OSO Energy binary sensor."""
|
||||
super().__init__(instance, entity_data)
|
||||
|
||||
device_id = entity_data.device_id
|
||||
self._attr_unique_id = f"{device_id}_{description.key}"
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self.entity_description.value_fn(self.entity_data)
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update all data for OSO Energy."""
|
||||
await self.osoenergy.session.update_data()
|
||||
self.entity_data = await self.osoenergy.binary_sensor.get_sensor(
|
||||
self.entity_data
|
||||
)
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"power_save": {
|
||||
"default": "mdi:power-sleep"
|
||||
},
|
||||
"extra_energy": {
|
||||
"default": "mdi:white-balance-sunny"
|
||||
},
|
||||
"heating": {
|
||||
"default": "mdi:water-boiler"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,17 @@
|
|||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"power_save": {
|
||||
"name": "Power save"
|
||||
},
|
||||
"extra_energy": {
|
||||
"name": "Extra energy"
|
||||
},
|
||||
"heating": {
|
||||
"name": "Heating"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"tapping_capacity": {
|
||||
"name": "Tapping capacity"
|
||||
|
|
Loading…
Reference in New Issue