2019-02-13 21:21:14 +01:00
|
|
|
"""Support for WeMo binary sensors."""
|
2018-12-19 02:12:32 -05:00
|
|
|
|
2022-05-22 23:43:42 -07:00
|
|
|
from pywemo import Insight, Maker, StandbyState
|
2021-08-22 11:09:22 -07:00
|
|
|
|
2020-04-23 21:57:07 +02:00
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
2021-12-19 16:09:30 -08:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2016-03-04 16:35:46 +00:00
|
|
|
|
2023-07-20 01:06:16 -07:00
|
|
|
from . import async_wemo_dispatcher_connect
|
2021-12-20 20:34:34 -08:00
|
|
|
from .entity import WemoBinaryStateEntity, WemoEntity
|
2021-12-19 16:09:30 -08:00
|
|
|
from .wemo_device import DeviceCoordinator
|
2019-04-11 23:37:45 -07:00
|
|
|
|
2016-03-04 16:35:46 +00:00
|
|
|
|
2021-12-19 16:09:30 -08:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
2023-07-20 01:06:16 -07:00
|
|
|
_config_entry: ConfigEntry,
|
2021-12-19 16:09:30 -08:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-01-19 12:56:31 -08:00
|
|
|
"""Set up WeMo binary sensors."""
|
2016-03-04 16:35:46 +00:00
|
|
|
|
2021-12-19 16:09:30 -08:00
|
|
|
async def _discovered_wemo(coordinator: DeviceCoordinator) -> None:
|
2020-01-19 12:56:31 -08:00
|
|
|
"""Handle a discovered Wemo device."""
|
2021-08-22 11:09:22 -07:00
|
|
|
if isinstance(coordinator.wemo, Insight):
|
|
|
|
async_add_entities([InsightBinarySensor(coordinator)])
|
|
|
|
elif isinstance(coordinator.wemo, Maker):
|
|
|
|
async_add_entities([MakerBinarySensor(coordinator)])
|
|
|
|
else:
|
|
|
|
async_add_entities([WemoBinarySensor(coordinator)])
|
2018-08-16 17:14:54 +03:00
|
|
|
|
2023-07-20 01:06:16 -07:00
|
|
|
await async_wemo_dispatcher_connect(hass, _discovered_wemo)
|
2016-03-04 16:35:46 +00:00
|
|
|
|
|
|
|
|
2021-12-20 20:34:34 -08:00
|
|
|
class WemoBinarySensor(WemoBinaryStateEntity, BinarySensorEntity):
|
2017-04-30 07:04:49 +02:00
|
|
|
"""Representation a WeMo binary sensor."""
|
2016-03-04 16:35:46 +00:00
|
|
|
|
2021-08-22 11:09:22 -07:00
|
|
|
|
|
|
|
class MakerBinarySensor(WemoEntity, BinarySensorEntity):
|
|
|
|
"""Maker device's sensor port."""
|
|
|
|
|
|
|
|
_name_suffix = "Sensor"
|
2022-05-24 00:53:01 -07:00
|
|
|
wemo: Maker
|
2021-08-22 11:09:22 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if the Maker's sensor is pulled low."""
|
2022-05-24 00:53:01 -07:00
|
|
|
return self.wemo.has_sensor != 0 and self.wemo.sensor_state == 0
|
2021-08-22 11:09:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
class InsightBinarySensor(WemoBinarySensor):
|
|
|
|
"""Sensor representing the device connected to the Insight Switch."""
|
|
|
|
|
|
|
|
_name_suffix = "Device"
|
2022-05-24 00:53:01 -07:00
|
|
|
wemo: Insight
|
2021-08-22 11:09:22 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true device connected to the Insight Switch is on."""
|
2022-05-24 00:53:01 -07:00
|
|
|
return super().is_on and self.wemo.standby_state == StandbyState.ON
|