Skip to content

Commit

Permalink
Update binary_sensor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarnsen authored Dec 23, 2024
1 parent 09fec5e commit 3d79eb7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion custom_components/xsense/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass

from xsense.device import Device
from xsense.entity import Entity
from xsense.station import Station
Expand All @@ -10,14 +13,24 @@
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
from .coordinator import XSenseDataUpdateCoordinator
from .entity import XSenseBinarySensorEntityDescription, XSenseEntity
from .entity import XSenseEntity


@dataclass(kw_only=True, frozen=True)
class XSenseBinarySensorEntityDescription(BinarySensorEntityDescription):
"""Describes XSense binary-sensor entity."""

exists_fn: Callable[[Entity], bool] = lambda _: True
value_fn: Callable[[Entity], bool]


SENSORS: tuple[XSenseBinarySensorEntityDescription, ...] = (
XSenseBinarySensorEntityDescription(
Expand Down Expand Up @@ -54,6 +67,14 @@
exists_fn=lambda entity: "activate" in entity.data,
value_fn=lambda entity: entity.data["activate"],
),
XSenseBinarySensorEntityDescription(
key="door",
translation_key="door",
device_class=BinarySensorDeviceClass.DOOR,
name="Door Sensor",
value_fn=lambda device: device.data["isOpen"] == "1",
exists_fn=lambda device: "isOpen" in device.data,
),
)

MQTTSensor = XSenseBinarySensorEntityDescription(
Expand Down

0 comments on commit 3d79eb7

Please sign in to comment.