Switch to different device api

This commit is contained in:
Luke Bonaccorsi 2023-09-12 16:40:55 +01:00
parent 5b787b9820
commit b48d12e05e
2 changed files with 28 additions and 35 deletions

View File

@ -93,10 +93,20 @@ def get_eufy_vacuums(self):
]
self[CONF_TIME_ZONE] = user_response["user_info"]["timezone"]
tuya_client = TuyaAPISession(
username="eh-" + self[CONF_CLIENT_ID],
region=self[CONF_REGION],
timezone=self[CONF_TIME_ZONE],
)
items = device_response["items"]
allvacs = {}
self[CONF_VACS] = {}
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"]))
vac_details = {
CONF_ID: item["device"]["id"],
CONF_MODEL: item["device"]["product"]["product_code"],
@ -105,33 +115,15 @@ def get_eufy_vacuums(self):
CONF_MAC: item["device"]["wifi"]["mac"],
CONF_IP_ADDRESS: "",
CONF_AUTODISCOVERY: True,
CONF_ACCESS_TOKEN: device["localKey"],
}
allvacs[item["device"]["id"]] = vac_details
tuya_client = TuyaAPISession(
username="eh-" + self[CONF_CLIENT_ID],
region=self[CONF_REGION],
timezone=self[CONF_TIME_ZONE],
self[CONF_VACS][item["device"]["id"]] = vac_details
except:
_LOGGER.debug(
"Vacuum {} found on Eufy, but not on Tuya. Skipping.".format(
item["device"]["id"]
)
)
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
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))
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."""

View File

@ -233,11 +233,11 @@ 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):