Skip to content

Commit

Permalink
Fix update issues with more than one robot
Browse files Browse the repository at this point in the history
  • Loading branch information
Sdahl1234 authored May 11, 2024
1 parent 063ac9c commit 9e14336
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion custom_components/sunseeker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(
self.always_update = True
self.data_handler = data_handler
self._devicesn = devicesn
self.data_handler._dataupdated = self.dataupdated
self.data_handler.get_device(devicesn)._dataupdated = self.dataupdated
self.filepath = os.path.join(
self.hass.config.config_dir,
"Schedule-{}.json".format(self._devicesn.replace(" ", "_")),
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sunseeker/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"integration_type": "device",
"iot_class": "cloud_push",
"config_flow": true,
"version": "1.0.12"
"version": "1.0.13"
}
64 changes: 33 additions & 31 deletions custom_components/sunseeker/sunseeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def __init__(self, Devicesn) -> None:
self.forceupdate = False
self.error_text = ""

self._dataupdated = None

self.DeviceModel = ""
self.DeviceName = ""
self.DeviceBluetooth = ""
Expand Down Expand Up @@ -182,7 +184,7 @@ def __init__(self, brand, email, password, language) -> None:
self.refresh_token_interval = None
self.refresh_token_timeout = None
self.robotList = []
self._dataupdated = None

self.login_ok: bool = False

def get_device(self, devicesn) -> SunseekerDevice:
Expand Down Expand Up @@ -392,8 +394,8 @@ def on_mqtt_message(self, client, userdata, message): # noqa: C901
if "Sun" in data:
device.Schedule.UpdateFromMqtt(data.get("Sun"), 7)
schedule = True
if self._dataupdated is not None:
self._dataupdated(device.devicesn, schedule)
if device._dataupdated is not None:
device._dataupdated(device.devicesn, schedule)
except Exception as error: # pylint: disable=broad-except
_LOGGER.debug("MQTT message error: " + str(error)) # noqa: G003
_LOGGER.debug("MQTT message: " + message.payload.decode()) # noqa: G003
Expand Down Expand Up @@ -483,8 +485,8 @@ def get_settings(self, snr):
_LOGGER.debug(f"Error getting device settings for {snr}") # noqa: G004
_LOGGER.debug(json.dumps(response_data))
return
if self._dataupdated is not None:
self._dataupdated(device.devicesn, False)
if device._dataupdated is not None:
device._dataupdated(device.devicesn, False)
return
except requests.exceptions.HTTPError as errh:
_LOGGER.debug(f"Get settings attempt {attempt}: Http Error: {errh}") # noqa: G004
Expand Down Expand Up @@ -542,8 +544,8 @@ def update_devices(self, device_sn):
if response_data["code"] != 0:
_LOGGER.debug(response_data)
continue
if self._dataupdated is not None:
self._dataupdated(device.devicesn, False)
if device._dataupdated is not None:
device._dataupdated(device.devicesn, False)
return

except Exception as error: # pylint: disable=broad-except
Expand Down Expand Up @@ -744,33 +746,33 @@ def set_schedule(
_LOGGER.debug(json.dumps(response_data))
if response_data.get("ok") is False:
self.get_device(devicesn).error_text = response_data.get("msg")
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(response_data.get("msg"))
else:
self.get_device(devicesn).error_text = ""
return

except requests.exceptions.HTTPError as errh:
self.get_device(devicesn).error_text = errh
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set schedule attempt {attempt}: Http Error: {errh}") # noqa: G004
except requests.exceptions.ConnectionError as errc:
self.get_device(devicesn).error_text = errc
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(
f"Set schedule attempt {attempt}: Error Connecting: {errc}" # noqa: G004
)
except requests.exceptions.Timeout as errt:
self.get_device(devicesn).error_text = errt
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set schedule attempt {attempt}: Timeout Error: {errt}") # noqa: G004
except requests.exceptions.RequestException as err:
self.get_device(devicesn).error_text = err
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set schedule attempt {attempt}: Error: {err}") # noqa: G004
except Exception as error: # pylint: disable=broad-except
self.get_device(devicesn).error_text = error
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set_schedule attempt {attempt}: failed {error}") # noqa: G004

def set_zone_status(
Expand Down Expand Up @@ -832,35 +834,35 @@ def set_zone_status(
_LOGGER.debug(json.dumps(response_data))
if response_data.get("ok") is False:
self.get_device(devicesn).error_text = response_data.get("msg")
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(response_data.get("msg"))
else:
self.get_device(devicesn).error_text = ""
return

except requests.exceptions.HTTPError as errh:
self.get_device(devicesn).error_text = errh
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set zone status attempt {attempt}: Http Error: {errh}") # noqa: G004
except requests.exceptions.ConnectionError as errc:
self.get_device(devicesn).error_text = errc
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(
f"Set zone status attempt {attempt}: Error Connecting: {errc}" # noqa: G004
)
except requests.exceptions.Timeout as errt:
self.get_device(devicesn).error_text = errt
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(
f"Set zone status attempt {attempt}: Timeout Error: {errt}" # noqa: G004
)
except requests.exceptions.RequestException as err:
self.get_device(devicesn).error_text = err
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set zone status attempt {attempt}: Error: {err}") # noqa: G004
except Exception as error: # pylint: disable=broad-except
self.get_device(devicesn).error_text = error
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set zone status attempt {attempt}: failed {error}") # noqa: G004

def set_rain_status(self, state: bool, delaymin: int, devicesn):
Expand Down Expand Up @@ -895,35 +897,35 @@ def set_rain_status(self, state: bool, delaymin: int, devicesn):
_LOGGER.debug(json.dumps(response_data))
if response_data.get("ok") is False:
self.get_device(devicesn).error_text = response_data.get("msg")
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(response_data.get("msg"))
else:
self.get_device(devicesn).error_text = ""
return

except requests.exceptions.HTTPError as errh:
self.get_device(devicesn).error_text = errh
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set rain status attempt {attempt}: Http Error: {errh}") # noqa: G004
except requests.exceptions.ConnectionError as errc:
self.get_device(devicesn).error_text = errc
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(
f"Set rain status attempt {attempt}: Error Connecting: {errc}" # noqa: G004
)
except requests.exceptions.Timeout as errt:
self.get_device(devicesn).error_text = errt
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(
f"Set rain status attempt {attempt}: Timeout Error: {errt}" # noqa: G004
)
except requests.exceptions.RequestException as err:
self.get_device(devicesn).error_text = err
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set rain status attempt {attempt}: Error: {err}") # noqa: G004
except Exception as error: # pylint: disable=broad-except
self.get_device(devicesn).error_text = error
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set rain status attempt {attempt}: failed {error}") # noqa: G004

def set_state_change(self, command, state, devicesn):
Expand Down Expand Up @@ -957,7 +959,7 @@ def set_state_change(self, command, state, devicesn):
_LOGGER.debug(json.dumps(response_data))
if response_data.get("ok") is False:
self.get_device(devicesn).error_text = response_data.get("msg")
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(response_data.get("msg"))
else:
self.get_device(devicesn).error_text = ""
Expand All @@ -968,27 +970,27 @@ def set_state_change(self, command, state, devicesn):

except requests.exceptions.HTTPError as errh:
self.get_device(devicesn).error_text = errh
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(
f"Set state change attempt {attempt}: Http Error: {errh}" # noqa: G004
)
except requests.exceptions.ConnectionError as errc:
self.get_device(devicesn).error_text = errc
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(
f"Set state change attempt {attempt}: Error Connecting: {errc}" # noqa: G004
)
except requests.exceptions.Timeout as errt:
self.get_device(devicesn).error_text = errt
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(
f"Set state change attempt {attempt}: Timeout Error: {errt}" # noqa: G004
)
except requests.exceptions.RequestException as err:
self.get_device(devicesn).error_text = err
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set state change attempt {attempt}: Error: {err}") # noqa: G004
except Exception as error: # pylint: disable=broad-except
self.get_device(devicesn).error_text = error
self._dataupdated(devicesn, False)
self.get_device(devicesn)._dataupdated(devicesn, False)
_LOGGER.debug(f"Set state change attempt {attempt}: failed {error}") # noqa: G004

0 comments on commit 9e14336

Please sign in to comment.