1 """Support for ThinkingCleaner sensors."""
3 from __future__
import annotations
5 from datetime
import timedelta
7 from pythinkingcleaner
import Discovery, ThinkingCleaner
8 import voluptuous
as vol
10 from homeassistant
import util
12 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
14 SensorEntityDescription,
23 MIN_TIME_BETWEEN_FORCED_SCANS =
timedelta(milliseconds=100)
25 SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
29 native_unit_of_measurement=PERCENTAGE,
43 "st_base":
"On homebase: Not Charging",
44 "st_base_recon":
"On homebase: Reconditioning Charging",
45 "st_base_full":
"On homebase: Full Charging",
46 "st_base_trickle":
"On homebase: Trickle Charging",
47 "st_base_wait":
"On homebase: Waiting",
48 "st_plug":
"Plugged in: Not Charging",
49 "st_plug_recon":
"Plugged in: Reconditioning Charging",
50 "st_plug_full":
"Plugged in: Full Charging",
51 "st_plug_trickle":
"Plugged in: Trickle Charging",
52 "st_plug_wait":
"Plugged in: Waiting",
53 "st_stopped":
"Stopped",
54 "st_clean":
"Cleaning",
55 "st_cleanstop":
"Stopped with cleaning",
56 "st_clean_spot":
"Spot cleaning",
57 "st_clean_max":
"Max cleaning",
58 "st_delayed":
"Delayed cleaning will start soon",
59 "st_dock":
"Searching Homebase",
60 "st_pickup":
"Roomba picked up",
61 "st_remote":
"Remote control driving",
62 "st_wait":
"Waiting for command",
65 "st_locate":
"Find me!",
66 "st_unknown":
"Unknown state",
69 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend({vol.Optional(CONF_HOST): cv.string})
75 add_entities: AddEntitiesCallback,
76 discovery_info: DiscoveryInfoType |
None =
None,
78 """Set up the ThinkingCleaner platform."""
79 if host := config.get(CONF_HOST):
80 devices = [ThinkingCleaner(host,
"unknown")]
82 discovery = Discovery()
83 devices = discovery.discover()
85 @util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
87 """Update all devices."""
88 for device_object
in devices:
89 device_object.update()
94 for description
in SENSOR_TYPES
101 """Representation of a ThinkingCleaner Sensor."""
104 self, tc_object, update_devices, description: SensorEntityDescription
106 """Initialize the ThinkingCleaner."""
111 self.
_attr_name_attr_name = f
"{tc_object.name} {description.name}"
114 """Update the sensor."""
118 if sensor_type ==
"battery":
120 elif sensor_type ==
"state":
122 elif sensor_type ==
"capacity":
None __init__(self, tc_object, update_devices, SensorEntityDescription description)
None update_devices(HomeAssistant hass, ConfigEntry config_entry, dict[int, Roller] api)
def add_entities(account, async_add_entities, tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)