Move cloud binary sensor to config entry (#106409)
* Move cloud binary sensor to config entry * Fix docstring
This commit is contained in:
parent
c8f9285aba
commit
e764372d1e
2 changed files with 10 additions and 21 deletions
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from hass_nabucasa import Cloud
|
||||
|
@ -11,11 +10,11 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .client import CloudClient
|
||||
from .const import DISPATCHER_REMOTE_UPDATE, DOMAIN
|
||||
|
@ -23,17 +22,13 @@ from .const import DISPATCHER_REMOTE_UPDATE, DOMAIN
|
|||
WAIT_UNTIL_CHANGE = 3
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the cloud binary sensors."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
cloud = hass.data[DOMAIN]
|
||||
|
||||
"""Set up the Home Assistant Cloud binary sensors."""
|
||||
cloud: Cloud[CloudClient] = hass.data[DOMAIN]
|
||||
async_add_entities([CloudRemoteBinary(cloud)])
|
||||
|
||||
|
||||
|
@ -49,7 +44,6 @@ class CloudRemoteBinary(BinarySensorEntity):
|
|||
def __init__(self, cloud: Cloud[CloudClient]) -> None:
|
||||
"""Initialize the binary sensor."""
|
||||
self.cloud = cloud
|
||||
self._unsub_dispatcher: Callable[[], None] | None = None
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
|
@ -69,12 +63,8 @@ class CloudRemoteBinary(BinarySensorEntity):
|
|||
await asyncio.sleep(WAIT_UNTIL_CHANGE)
|
||||
self.async_write_ha_state()
|
||||
|
||||
self._unsub_dispatcher = async_dispatcher_connect(
|
||||
self.hass, DISPATCHER_REMOTE_UPDATE, async_state_update
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, DISPATCHER_REMOTE_UPDATE, async_state_update
|
||||
)
|
||||
)
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Register update dispatcher."""
|
||||
if self._unsub_dispatcher is not None:
|
||||
self._unsub_dispatcher()
|
||||
self._unsub_dispatcher = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue