diff --git a/custom_components/robovac/config_flow.py b/custom_components/robovac/config_flow.py index 118d316..f355d87 100644 --- a/custom_components/robovac/config_flow.py +++ b/custom_components/robovac/config_flow.py @@ -93,45 +93,37 @@ def get_eufy_vacuums(self): ] self[CONF_TIME_ZONE] = user_response["user_info"]["timezone"] - items = device_response["items"] - allvacs = {} - for item in items: - if item["device"]["product"]["appliance"] == "Cleaning": - vac_details = { - CONF_ID: item["device"]["id"], - CONF_MODEL: item["device"]["product"]["product_code"], - CONF_NAME: item["device"]["alias_name"], - CONF_DESCRIPTION: item["device"]["name"], - CONF_MAC: item["device"]["wifi"]["mac"], - CONF_IP_ADDRESS: "", - CONF_AUTODISCOVERY: True, - } - allvacs[item["device"]["id"]] = vac_details - tuya_client = TuyaAPISession( username="eh-" + self[CONF_CLIENT_ID], region=self[CONF_REGION], timezone=self[CONF_TIME_ZONE], ) + items = device_response["items"] self[CONF_VACS] = {} - for home in tuya_client.list_homes(): - for device in tuya_client.list_devices(home["groupId"]): - if device["devId"] not in allvacs: - _LOGGER.debug("Vacuum {} found on Tuya, but not on Eufy. Skipping.".format(device["devId"])) - continue + for item in items: + if item["device"]["product"]["appliance"] == "Cleaning": + try: + device = tuya_client.get_device(item["device"]["id"]) + _LOGGER.debug("Robovac schema: {}".format(device["schema"])) - if "localKey" not in device or not device["localKey"]: - _LOGGER.error("Local key missing for vacuum {} ({}) in data from Tuya. Skipping.".format(allvacs[device["devId"]][CONF_NAME], device["devId"])) - continue - - allvacs[device["devId"]][CONF_ACCESS_TOKEN] = device["localKey"] - allvacs[device["devId"]][CONF_LOCATION] = home["groupId"] - self[CONF_VACS][device["devId"]] = allvacs[device["devId"]] - - for vacuum_id in allvacs: - if vacuum_id not in self[CONF_VACS]: - _LOGGER.error("Vacuum {} ({}) found on Eufy, but not on Tuya. Vacuum will not be added.".format(allvacs[vacuum_id][CONF_NAME], vacuum_id)) + vac_details = { + CONF_ID: item["device"]["id"], + CONF_MODEL: item["device"]["product"]["product_code"], + CONF_NAME: item["device"]["alias_name"], + CONF_DESCRIPTION: item["device"]["name"], + CONF_MAC: item["device"]["wifi"]["mac"], + CONF_IP_ADDRESS: "", + CONF_AUTODISCOVERY: True, + CONF_ACCESS_TOKEN: device["localKey"], + } + self[CONF_VACS][item["device"]["id"]] = vac_details + except: + _LOGGER.debug( + "Vacuum {} found on Eufy, but not on Tuya. Skipping.".format( + item["device"]["id"] + ) + ) return response @@ -187,6 +179,7 @@ class CannotConnect(HomeAssistantError): class InvalidAuth(HomeAssistantError): """Error to indicate there is invalid auth.""" + class OptionsFlowHandler(config_entries.OptionsFlow): """Handles options flow for the component.""" diff --git a/custom_components/robovac/tuyawebapi.py b/custom_components/robovac/tuyawebapi.py index 94226c5..bde34d2 100644 --- a/custom_components/robovac/tuyawebapi.py +++ b/custom_components/robovac/tuyawebapi.py @@ -232,12 +232,12 @@ class TuyaAPISession: def list_homes(self): return self._request(action="tuya.m.location.list", version="2.1") - - def list_devices(self, home_id: str): + + def get_device(self, devId): return self._request( - action="tuya.m.my.group.device.list", + action="tuya.m.device.get", version="1.0", - query_params={"gid": home_id}, + data={"devId": devId} ) def getCountryCode(self, region_code):