1 """Support for ThinkingCleaner switches."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 from pythinkingcleaner
import Discovery, ThinkingCleaner
10 import voluptuous
as vol
12 from homeassistant
import util
14 PLATFORM_SCHEMA
as SWITCH_PLATFORM_SCHEMA,
16 SwitchEntityDescription,
25 MIN_TIME_BETWEEN_FORCED_SCANS =
timedelta(milliseconds=100)
28 MIN_TIME_TO_LOCK_UPDATE = 5
30 SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
45 PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend({vol.Optional(CONF_HOST): cv.string})
51 add_entities: AddEntitiesCallback,
52 discovery_info: DiscoveryInfoType |
None =
None,
54 """Set up the ThinkingCleaner platform."""
55 if host := config.get(CONF_HOST):
56 devices = [ThinkingCleaner(host,
"unknown")]
58 discovery = Discovery()
59 devices = discovery.discover()
61 @util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
63 """Update all devices."""
64 for device_object
in devices:
65 device_object.update()
70 for description
in SWITCH_TYPES
77 """ThinkingCleaner Switch (dock, clean, find me)."""
80 self, tc_object, update_devices, description: SwitchEntityDescription
82 """Initialize the ThinkingCleaner."""
88 self.
_tc_object_tc_object.is_cleaning
if description.key ==
"clean" else False
94 self.
_attr_name_attr_name = f
"{tc_object.name} {description.name}"
97 """Lock the update since TC clean takes some time to update."""
104 """Reset the update lock."""
105 self.
locklock =
False
109 """Set the graceful state."""
115 """Check if the update method is locked."""
119 if time.time() - self.
last_lock_timelast_lock_time >= MIN_TIME_TO_LOCK_UPDATE:
127 """Return true if device is on."""
138 """Turn the device on."""
140 if sensor_type ==
"clean":
143 elif sensor_type ==
"dock":
145 elif sensor_type ==
"find":
149 """Turn the device off."""
155 """Update the switch state (Only for clean)."""
158 self.
_state_state = STATE_ON
if self.
_tc_object_tc_object.is_cleaning
else STATE_OFF
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
def is_update_locked(self)
def reset_update_lock(self)
def set_graceful_lock(self, state)
None __init__(self, tc_object, update_devices, SwitchEntityDescription description)
None update_devices(HomeAssistant hass, ConfigEntry config_entry, dict[int, Roller] api)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)