hass-core/homeassistant/components/lupusec/binary_sensor.py
suaveolent f2100f80c4
Add device info to lupusec (#108910)
* added device info and unique id

* removed wrong attribute

* added base entity

* rename domain

* added entity.py to coveragerc

* added base entity for sensors and alarm panel

* add generic type translation

* rename functions

* rename device name to device model

* set _attr_name = None

* pass in only the entry_id instead of the full config_entry

* set unique id to device_id or entry id

* use deviceinfo class

* moved     _attr_name = None to entities

* Update homeassistant/components/lupusec/alarm_control_panel.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/lupusec/entity.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/lupusec/entity.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* remove DOMAIN from unique id

* removed redundant function

* Update homeassistant/components/lupusec/alarm_control_panel.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/lupusec/entity.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

---------

Co-authored-by: suaveolent <suaveolent@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-01-28 16:06:57 +01:00

60 lines
1.6 KiB
Python

"""Support for Lupusec Security System binary sensors."""
from __future__ import annotations
from datetime import timedelta
import logging
import lupupy.constants as CONST
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import DOMAIN
from .entity import LupusecBaseSensor
SCAN_INTERVAL = timedelta(seconds=2)
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_devices: AddEntitiesCallback,
) -> None:
"""Set up a binary sensors for a Lupusec device."""
data = hass.data[DOMAIN][config_entry.entry_id]
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
sensors = []
for device in data.lupusec.get_devices(generic_type=device_types):
sensors.append(LupusecBinarySensor(data, device, config_entry.entry_id))
async_add_devices(sensors)
class LupusecBinarySensor(LupusecBaseSensor, BinarySensorEntity):
"""A binary sensor implementation for Lupusec device."""
_attr_name = None
@property
def is_on(self):
"""Return True if the binary sensor is on."""
return self._device.is_on
@property
def device_class(self):
"""Return the class of the binary sensor."""
if self._device.generic_type not in (
item.value for item in BinarySensorDeviceClass
):
return None
return self._device.generic_type