Use switch instead of toggle entity (#55111)

This commit is contained in:
Marc Mueller 2021-08-24 10:22:06 +02:00 committed by GitHub
parent a08f42e516
commit 9f4f38dbef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,10 +8,13 @@ from pythinkingcleaner import Discovery, ThinkingCleaner
import voluptuous as vol import voluptuous as vol
from homeassistant import util from homeassistant import util
from homeassistant.components.switch import PLATFORM_SCHEMA from homeassistant.components.switch import (
PLATFORM_SCHEMA,
SwitchEntity,
SwitchEntityDescription,
)
from homeassistant.const import CONF_HOST, STATE_OFF, STATE_ON from homeassistant.const import CONF_HOST, STATE_OFF, STATE_ON
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100) MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
@ -19,16 +22,16 @@ MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
MIN_TIME_TO_WAIT = timedelta(seconds=5) MIN_TIME_TO_WAIT = timedelta(seconds=5)
MIN_TIME_TO_LOCK_UPDATE = 5 MIN_TIME_TO_LOCK_UPDATE = 5
SWITCH_TYPES: tuple[ToggleEntityDescription, ...] = ( SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
ToggleEntityDescription( SwitchEntityDescription(
key="clean", key="clean",
name="Clean", name="Clean",
), ),
ToggleEntityDescription( SwitchEntityDescription(
key="dock", key="dock",
name="Dock", name="Dock",
), ),
ToggleEntityDescription( SwitchEntityDescription(
key="find", key="find",
name="Find", name="Find",
), ),
@ -61,10 +64,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(entities) add_entities(entities)
class ThinkingCleanerSwitch(ToggleEntity): class ThinkingCleanerSwitch(SwitchEntity):
"""ThinkingCleaner Switch (dock, clean, find me).""" """ThinkingCleaner Switch (dock, clean, find me)."""
def __init__(self, tc_object, update_devices, description: ToggleEntityDescription): def __init__(self, tc_object, update_devices, description: SwitchEntityDescription):
"""Initialize the ThinkingCleaner.""" """Initialize the ThinkingCleaner."""
self.entity_description = description self.entity_description = description