1 """Support for Neato Connected Vacuums switches."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 from pybotvac.exceptions
import NeatoRobotException
10 from pybotvac.robot
import Robot
18 from .const
import NEATO_LOGIN, NEATO_ROBOTS, SCAN_INTERVAL_MINUTES
19 from .entity
import NeatoEntity
20 from .hub
import NeatoHub
22 _LOGGER = logging.getLogger(__name__)
24 SCAN_INTERVAL =
timedelta(minutes=SCAN_INTERVAL_MINUTES)
26 SWITCH_TYPE_SCHEDULE =
"schedule"
28 SWITCH_TYPES = {SWITCH_TYPE_SCHEDULE: [
"Schedule"]}
32 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
34 """Set up Neato switch with config entry."""
35 neato: NeatoHub = hass.data[NEATO_LOGIN]
38 for robot
in hass.data[NEATO_ROBOTS]
39 for type_name
in SWITCH_TYPES
45 _LOGGER.debug(
"Adding switches %s", dev)
50 """Neato Connected Switches."""
52 _attr_translation_key =
"schedule"
53 _attr_available =
False
54 _attr_entity_category = EntityCategory.CONFIG
56 def __init__(self, neato: NeatoHub, robot: Robot, switch_type: str) ->
None:
57 """Initialize the Neato Connected switches."""
59 self.
typetype = switch_type
60 self.
_state_state: dict[str, Any] |
None =
None
66 """Update the states of Neato switches."""
67 _LOGGER.debug(
"Running Neato switch update for '%s'", self.
entity_identity_id)
70 except NeatoRobotException
as ex:
73 "Neato switch connection error for '%s': %s", self.
entity_identity_id, ex
80 _LOGGER.debug(
"self._state=%s", self.
_state_state)
81 if self.
typetype == SWITCH_TYPE_SCHEDULE:
82 _LOGGER.debug(
"State: %s", self.
_state_state)
83 if self.
_state_state
is not None and self.
_state_state[
"details"][
"isScheduleEnabled"]:
93 """Return true if switch is on."""
99 """Turn the switch on."""
100 if self.
typetype == SWITCH_TYPE_SCHEDULE:
102 self.
robotrobot.enable_schedule()
103 except NeatoRobotException
as ex:
105 "Neato switch connection error '%s': %s", self.
entity_identity_id, ex
109 """Turn the switch off."""
110 if self.
typetype == SWITCH_TYPE_SCHEDULE:
112 self.
robotrobot.disable_schedule()
113 except NeatoRobotException
as ex:
115 "Neato switch connection error '%s': %s", self.
entity_identity_id, ex
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
None __init__(self, NeatoHub neato, Robot robot, str switch_type)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)