2019-02-13 21:21:14 +01:00
|
|
|
"""Support for WeMo binary sensors."""
|
2018-12-19 02:12:32 -05:00
|
|
|
import asyncio
|
2016-03-04 16:35:46 +00:00
|
|
|
import logging
|
2018-12-19 02:12:32 -05:00
|
|
|
|
2020-04-23 21:57:07 +02:00
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
2020-01-19 12:56:31 -08:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2016-03-04 16:35:46 +00:00
|
|
|
|
2020-01-19 12:56:31 -08:00
|
|
|
from .const import DOMAIN as WEMO_DOMAIN
|
2021-08-21 11:14:55 -07:00
|
|
|
from .entity import WemoEntity
|
2019-04-11 23:37:45 -07:00
|
|
|
|
2016-03-04 16:35:46 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2020-01-19 12:56:31 -08:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up WeMo binary sensors."""
|
2016-03-04 16:35:46 +00:00
|
|
|
|
2021-08-21 11:14:55 -07:00
|
|
|
async def _discovered_wemo(coordinator):
|
2020-01-19 12:56:31 -08:00
|
|
|
"""Handle a discovered Wemo device."""
|
2021-08-21 11:14:55 -07:00
|
|
|
async_add_entities([WemoBinarySensor(coordinator)])
|
2018-08-16 17:14:54 +03:00
|
|
|
|
2020-01-19 12:56:31 -08:00
|
|
|
async_dispatcher_connect(hass, f"{WEMO_DOMAIN}.binary_sensor", _discovered_wemo)
|
2016-03-04 16:35:46 +00:00
|
|
|
|
2020-01-19 12:56:31 -08:00
|
|
|
await asyncio.gather(
|
2021-07-19 11:46:09 +03:00
|
|
|
*(
|
2021-08-21 11:14:55 -07:00
|
|
|
_discovered_wemo(coordinator)
|
|
|
|
for coordinator in hass.data[WEMO_DOMAIN]["pending"].pop("binary_sensor")
|
2021-07-19 11:46:09 +03:00
|
|
|
)
|
2020-01-19 12:56:31 -08:00
|
|
|
)
|
2016-03-04 16:35:46 +00:00
|
|
|
|
|
|
|
|
2021-08-21 11:14:55 -07:00
|
|
|
class WemoBinarySensor(WemoEntity, BinarySensorEntity):
|
2017-04-30 07:04:49 +02:00
|
|
|
"""Representation a WeMo binary sensor."""
|
2016-03-04 16:35:46 +00:00
|
|
|
|
2021-08-21 11:14:55 -07:00
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if the state is on. Standby is on."""
|
|
|
|
return self.wemo.get_state()
|