mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add occupancy sensor to the BAF integration (#75793)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
33c635809c
commit
89493f2d7f
@ -15,6 +15,7 @@ from .const import DOMAIN, QUERY_INTERVAL, RUN_TIMEOUT
|
|||||||
from .models import BAFData
|
from .models import BAFData
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [
|
PLATFORMS: list[Platform] = [
|
||||||
|
Platform.BINARY_SENSOR,
|
||||||
Platform.CLIMATE,
|
Platform.CLIMATE,
|
||||||
Platform.FAN,
|
Platform.FAN,
|
||||||
Platform.LIGHT,
|
Platform.LIGHT,
|
||||||
|
80
homeassistant/components/baf/binary_sensor.py
Normal file
80
homeassistant/components/baf/binary_sensor.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
"""Support for Big Ass Fans binary sensors."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import Optional, cast
|
||||||
|
|
||||||
|
from aiobafi6 import Device
|
||||||
|
|
||||||
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components.binary_sensor import (
|
||||||
|
BinarySensorDeviceClass,
|
||||||
|
BinarySensorEntity,
|
||||||
|
BinarySensorEntityDescription,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .entity import BAFEntity
|
||||||
|
from .models import BAFData
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BAFBinarySensorDescriptionMixin:
|
||||||
|
"""Required values for BAF binary sensors."""
|
||||||
|
|
||||||
|
value_fn: Callable[[Device], bool | None]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BAFBinarySensorDescription(
|
||||||
|
BinarySensorEntityDescription,
|
||||||
|
BAFBinarySensorDescriptionMixin,
|
||||||
|
):
|
||||||
|
"""Class describing BAF binary sensor entities."""
|
||||||
|
|
||||||
|
|
||||||
|
OCCUPANCY_SENSORS = (
|
||||||
|
BAFBinarySensorDescription(
|
||||||
|
key="occupancy",
|
||||||
|
name="Occupancy",
|
||||||
|
device_class=BinarySensorDeviceClass.OCCUPANCY,
|
||||||
|
value_fn=lambda device: cast(Optional[bool], device.fan_occupancy_detected),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: config_entries.ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up BAF binary sensors."""
|
||||||
|
data: BAFData = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
device = data.device
|
||||||
|
sensors_descriptions: list[BAFBinarySensorDescription] = []
|
||||||
|
if device.has_occupancy:
|
||||||
|
sensors_descriptions.extend(OCCUPANCY_SENSORS)
|
||||||
|
async_add_entities(
|
||||||
|
BAFBinarySensor(device, description) for description in sensors_descriptions
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class BAFBinarySensor(BAFEntity, BinarySensorEntity):
|
||||||
|
"""BAF binary sensor."""
|
||||||
|
|
||||||
|
entity_description: BAFBinarySensorDescription
|
||||||
|
|
||||||
|
def __init__(self, device: Device, description: BAFBinarySensorDescription) -> None:
|
||||||
|
"""Initialize the entity."""
|
||||||
|
self.entity_description = description
|
||||||
|
super().__init__(device, f"{device.name} {description.name}")
|
||||||
|
self._attr_unique_id = f"{self._device.mac_address}-{description.key}"
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_update_attrs(self) -> None:
|
||||||
|
"""Update attrs from device."""
|
||||||
|
description = self.entity_description
|
||||||
|
self._attr_is_on = description.value_fn(self._device)
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Big Ass Fans",
|
"name": "Big Ass Fans",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/baf",
|
"documentation": "https://www.home-assistant.io/integrations/baf",
|
||||||
"requirements": ["aiobafi6==0.6.0"],
|
"requirements": ["aiobafi6==0.7.0"],
|
||||||
"codeowners": ["@bdraco", "@jfroy"],
|
"codeowners": ["@bdraco", "@jfroy"],
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"zeroconf": [
|
"zeroconf": [
|
||||||
|
@ -128,7 +128,7 @@ aioasuswrt==1.4.0
|
|||||||
aioazuredevops==1.3.5
|
aioazuredevops==1.3.5
|
||||||
|
|
||||||
# homeassistant.components.baf
|
# homeassistant.components.baf
|
||||||
aiobafi6==0.6.0
|
aiobafi6==0.7.0
|
||||||
|
|
||||||
# homeassistant.components.aws
|
# homeassistant.components.aws
|
||||||
aiobotocore==2.1.0
|
aiobotocore==2.1.0
|
||||||
|
@ -115,7 +115,7 @@ aioasuswrt==1.4.0
|
|||||||
aioazuredevops==1.3.5
|
aioazuredevops==1.3.5
|
||||||
|
|
||||||
# homeassistant.components.baf
|
# homeassistant.components.baf
|
||||||
aiobafi6==0.6.0
|
aiobafi6==0.7.0
|
||||||
|
|
||||||
# homeassistant.components.aws
|
# homeassistant.components.aws
|
||||||
aiobotocore==2.1.0
|
aiobotocore==2.1.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user