1
mirror of https://github.com/home-assistant/core synced 2024-08-28 03:36:46 +02:00

Move cloud binary sensor to config entry (#106409)

* Move cloud binary sensor to config entry

* Fix docstring
This commit is contained in:
Martin Hjelmare 2023-12-26 15:12:37 +01:00 committed by GitHub
parent c8f9285aba
commit e764372d1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 21 deletions

View File

@ -63,7 +63,7 @@ from .subscription import async_subscription_info
DEFAULT_MODE = MODE_PROD
PLATFORMS = [Platform.STT]
PLATFORMS = [Platform.BINARY_SENSOR, Platform.STT]
SERVICE_REMOTE_CONNECT = "remote_connect"
SERVICE_REMOTE_DISCONNECT = "remote_disconnect"
@ -284,7 +284,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
tts_info = {"platform_loaded": tts_platform_loaded}
await async_load_platform(hass, Platform.BINARY_SENSOR, DOMAIN, {}, config)
await async_load_platform(hass, Platform.TTS, DOMAIN, tts_info, config)
await tts_platform_loaded.wait()

View File

@ -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