mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Neato reduce API calls (#29156)
* initial commit * Fix a bug where some values are not available * Workaround if git_robot_info() is not available
This commit is contained in:
parent
bb46918d2e
commit
c0619944fa
@ -21,7 +21,6 @@ from .const import (
|
|||||||
NEATO_MAP_DATA,
|
NEATO_MAP_DATA,
|
||||||
NEATO_PERSISTENT_MAPS,
|
NEATO_PERSISTENT_MAPS,
|
||||||
NEATO_ROBOTS,
|
NEATO_ROBOTS,
|
||||||
SCAN_INTERVAL_MINUTES,
|
|
||||||
VALID_VENDORS,
|
VALID_VENDORS,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -161,7 +160,7 @@ class NeatoHub:
|
|||||||
self.logged_in = True
|
self.logged_in = True
|
||||||
_LOGGER.debug("Successfully connected to Neato API")
|
_LOGGER.debug("Successfully connected to Neato API")
|
||||||
|
|
||||||
@Throttle(timedelta(minutes=SCAN_INTERVAL_MINUTES))
|
@Throttle(timedelta(minutes=1))
|
||||||
def update_robots(self):
|
def update_robots(self):
|
||||||
"""Update the robot states."""
|
"""Update the robot states."""
|
||||||
_LOGGER.debug("Running HUB.update_robots %s", self._hass.data.get(NEATO_ROBOTS))
|
_LOGGER.debug("Running HUB.update_robots %s", self._hass.data.get(NEATO_ROBOTS))
|
||||||
|
@ -41,22 +41,14 @@ class NeatoSensor(Entity):
|
|||||||
def __init__(self, neato, robot):
|
def __init__(self, neato, robot):
|
||||||
"""Initialize Neato sensor."""
|
"""Initialize Neato sensor."""
|
||||||
self.robot = robot
|
self.robot = robot
|
||||||
self.neato = neato
|
self._available = neato.logged_in if neato is not None else False
|
||||||
self._available = self.neato.logged_in if self.neato is not None else False
|
|
||||||
self._robot_name = f"{self.robot.name} {BATTERY}"
|
self._robot_name = f"{self.robot.name} {BATTERY}"
|
||||||
self._robot_serial = self.robot.serial
|
self._robot_serial = self.robot.serial
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update Neato Sensor."""
|
"""Update Neato Sensor."""
|
||||||
if self.neato is None:
|
|
||||||
_LOGGER.error("Error while updating sensor")
|
|
||||||
self._state = None
|
|
||||||
self._available = False
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.neato.update_robots()
|
|
||||||
self._state = self.robot.state
|
self._state = self.robot.state
|
||||||
except NeatoRobotException as ex:
|
except NeatoRobotException as ex:
|
||||||
if self._available:
|
if self._available:
|
||||||
|
@ -45,8 +45,7 @@ class NeatoConnectedSwitch(ToggleEntity):
|
|||||||
"""Initialize the Neato Connected switches."""
|
"""Initialize the Neato Connected switches."""
|
||||||
self.type = switch_type
|
self.type = switch_type
|
||||||
self.robot = robot
|
self.robot = robot
|
||||||
self.neato = neato
|
self._available = neato.logged_in if neato is not None else False
|
||||||
self._available = self.neato.logged_in if self.neato is not None else False
|
|
||||||
self._robot_name = f"{self.robot.name} {SWITCH_TYPES[self.type][0]}"
|
self._robot_name = f"{self.robot.name} {SWITCH_TYPES[self.type][0]}"
|
||||||
self._state = None
|
self._state = None
|
||||||
self._schedule_state = None
|
self._schedule_state = None
|
||||||
@ -55,15 +54,8 @@ class NeatoConnectedSwitch(ToggleEntity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the states of Neato switches."""
|
"""Update the states of Neato switches."""
|
||||||
if self.neato is None:
|
|
||||||
_LOGGER.error("Error while updating switches")
|
|
||||||
self._state = None
|
|
||||||
self._available = False
|
|
||||||
return
|
|
||||||
|
|
||||||
_LOGGER.debug("Running switch update")
|
_LOGGER.debug("Running switch update")
|
||||||
try:
|
try:
|
||||||
self.neato.update_robots()
|
|
||||||
self._state = self.robot.state
|
self._state = self.robot.state
|
||||||
except NeatoRobotException as ex:
|
except NeatoRobotException as ex:
|
||||||
if self._available: # Print only once when available
|
if self._available: # Print only once when available
|
||||||
|
@ -137,8 +137,7 @@ class NeatoConnectedVacuum(StateVacuumDevice):
|
|||||||
def __init__(self, neato, robot, mapdata, persistent_maps):
|
def __init__(self, neato, robot, mapdata, persistent_maps):
|
||||||
"""Initialize the Neato Connected Vacuum."""
|
"""Initialize the Neato Connected Vacuum."""
|
||||||
self.robot = robot
|
self.robot = robot
|
||||||
self.neato = neato
|
self._available = neato.logged_in if neato is not None else False
|
||||||
self._available = self.neato.logged_in if self.neato is not None else False
|
|
||||||
self._mapdata = mapdata
|
self._mapdata = mapdata
|
||||||
self._name = f"{self.robot.name}"
|
self._name = f"{self.robot.name}"
|
||||||
self._robot_has_map = self.robot.has_persistent_maps
|
self._robot_has_map = self.robot.has_persistent_maps
|
||||||
@ -163,17 +162,14 @@ class NeatoConnectedVacuum(StateVacuumDevice):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the states of Neato Vacuums."""
|
"""Update the states of Neato Vacuums."""
|
||||||
if self.neato is None:
|
|
||||||
_LOGGER.error("Error while updating vacuum")
|
|
||||||
self._state = None
|
|
||||||
self._available = False
|
|
||||||
return
|
|
||||||
|
|
||||||
_LOGGER.debug("Running Neato Vacuums update")
|
_LOGGER.debug("Running Neato Vacuums update")
|
||||||
try:
|
try:
|
||||||
if self._robot_stats is None:
|
if self._robot_stats is None:
|
||||||
self._robot_stats = self.robot.get_robot_info().json()
|
self._robot_stats = self.robot.get_robot_info().json()
|
||||||
self.neato.update_robots()
|
except NeatoRobotException:
|
||||||
|
_LOGGER.warning("Couldn't fetch robot information of %s", self._name)
|
||||||
|
|
||||||
|
try:
|
||||||
self._state = self.robot.state
|
self._state = self.robot.state
|
||||||
except NeatoRobotException as ex:
|
except NeatoRobotException as ex:
|
||||||
if self._available: # print only once when available
|
if self._available: # print only once when available
|
||||||
@ -321,13 +317,12 @@ class NeatoConnectedVacuum(StateVacuumDevice):
|
|||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
"""Device info for neato robot."""
|
"""Device info for neato robot."""
|
||||||
return {
|
info = {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}, "name": self._name}
|
||||||
"identifiers": {(NEATO_DOMAIN, self._robot_serial)},
|
if self._robot_stats:
|
||||||
"name": self._name,
|
info["manufacturer"] = self._robot_stats["data"]["mfg_name"]
|
||||||
"manufacturer": self._robot_stats["data"]["mfg_name"],
|
info["model"] = self._robot_stats["data"]["modelName"]
|
||||||
"model": self._robot_stats["data"]["modelName"],
|
if self._state:
|
||||||
"sw_version": self._state["meta"]["firmware"],
|
info["sw_version"] = self._state["meta"]["firmware"]
|
||||||
}
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start cleaning or resume cleaning."""
|
"""Start cleaning or resume cleaning."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user