2019-04-03 15:40:03 +00:00
|
|
|
"""Demo platform that has two fake binary sensors."""
|
2022-01-03 12:10:41 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-09-12 21:20:30 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-01 07:12:09 +00:00
|
|
|
BinarySensorDeviceClass,
|
2020-09-12 21:20:30 +00:00
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
2022-01-03 12:10:41 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
2023-08-11 02:04:26 +00:00
|
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
2022-01-03 12:10:41 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-12-08 16:59:27 +00:00
|
|
|
|
2019-11-13 15:37:31 +00:00
|
|
|
from . import DOMAIN
|
2015-11-19 18:00:22 +00:00
|
|
|
|
|
|
|
|
2023-06-14 14:50:35 +00:00
|
|
|
async def async_setup_entry(
|
2022-01-03 12:10:41 +00:00
|
|
|
hass: HomeAssistant,
|
2023-06-14 14:50:35 +00:00
|
|
|
config_entry: ConfigEntry,
|
2022-01-03 12:10:41 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2023-06-14 14:50:35 +00:00
|
|
|
"""Set up the demo binary sensor platform."""
|
2019-11-13 15:37:31 +00:00
|
|
|
async_add_entities(
|
2019-07-31 19:25:30 +00:00
|
|
|
[
|
2020-09-13 14:33:54 +00:00
|
|
|
DemoBinarySensor(
|
2021-12-01 07:12:09 +00:00
|
|
|
"binary_1",
|
|
|
|
"Basement Floor Wet",
|
|
|
|
False,
|
|
|
|
BinarySensorDeviceClass.MOISTURE,
|
2020-09-13 14:33:54 +00:00
|
|
|
),
|
2020-09-12 21:20:30 +00:00
|
|
|
DemoBinarySensor(
|
2021-12-01 07:12:09 +00:00
|
|
|
"binary_2", "Movement Backyard", True, BinarySensorDeviceClass.MOTION
|
2020-09-12 21:20:30 +00:00
|
|
|
),
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
|
|
|
)
|
2015-11-19 18:00:22 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class DemoBinarySensor(BinarySensorEntity):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""representation of a Demo binary sensor."""
|
2016-03-07 19:21:08 +00:00
|
|
|
|
2023-06-14 14:50:35 +00:00
|
|
|
_attr_has_entity_name = True
|
2023-06-19 13:56:48 +00:00
|
|
|
_attr_name = None
|
2022-08-28 22:51:10 +00:00
|
|
|
_attr_should_poll = False
|
|
|
|
|
2021-12-01 07:12:09 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
unique_id: str,
|
2023-06-14 14:50:35 +00:00
|
|
|
device_name: str,
|
2021-12-01 07:12:09 +00:00
|
|
|
state: bool,
|
|
|
|
device_class: BinarySensorDeviceClass,
|
|
|
|
) -> None:
|
2016-03-07 19:21:08 +00:00
|
|
|
"""Initialize the demo sensor."""
|
2019-11-13 15:37:31 +00:00
|
|
|
self._unique_id = unique_id
|
2015-11-19 18:00:22 +00:00
|
|
|
self._state = state
|
2022-09-14 17:09:31 +00:00
|
|
|
self._attr_device_class = device_class
|
2023-06-14 14:50:35 +00:00
|
|
|
self._attr_device_info = DeviceInfo(
|
2021-10-22 15:00:00 +00:00
|
|
|
identifiers={
|
2019-11-13 15:37:31 +00:00
|
|
|
# Serial numbers are unique identifiers within a specific domain
|
|
|
|
(DOMAIN, self.unique_id)
|
|
|
|
},
|
2023-06-14 14:50:35 +00:00
|
|
|
name=device_name,
|
2021-10-22 15:00:00 +00:00
|
|
|
)
|
2019-11-13 15:37:31 +00:00
|
|
|
|
|
|
|
@property
|
2022-06-30 13:34:48 +00:00
|
|
|
def unique_id(self) -> str:
|
2019-11-13 15:37:31 +00:00
|
|
|
"""Return the unique id."""
|
|
|
|
return self._unique_id
|
|
|
|
|
2015-11-19 18:00:22 +00:00
|
|
|
@property
|
2022-06-30 13:34:48 +00:00
|
|
|
def is_on(self) -> bool:
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return true if the binary sensor is on."""
|
2015-11-19 18:00:22 +00:00
|
|
|
return self._state
|