Switch to different device api
This commit is contained in:
parent
5b787b9820
commit
b48d12e05e
|
|
@ -93,45 +93,37 @@ def get_eufy_vacuums(self):
|
||||||
]
|
]
|
||||||
self[CONF_TIME_ZONE] = user_response["user_info"]["timezone"]
|
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(
|
tuya_client = TuyaAPISession(
|
||||||
username="eh-" + self[CONF_CLIENT_ID],
|
username="eh-" + self[CONF_CLIENT_ID],
|
||||||
region=self[CONF_REGION],
|
region=self[CONF_REGION],
|
||||||
timezone=self[CONF_TIME_ZONE],
|
timezone=self[CONF_TIME_ZONE],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
items = device_response["items"]
|
||||||
self[CONF_VACS] = {}
|
self[CONF_VACS] = {}
|
||||||
for home in tuya_client.list_homes():
|
for item in items:
|
||||||
for device in tuya_client.list_devices(home["groupId"]):
|
if item["device"]["product"]["appliance"] == "Cleaning":
|
||||||
if device["devId"] not in allvacs:
|
try:
|
||||||
_LOGGER.debug("Vacuum {} found on Tuya, but not on Eufy. Skipping.".format(device["devId"]))
|
device = tuya_client.get_device(item["device"]["id"])
|
||||||
continue
|
_LOGGER.debug("Robovac schema: {}".format(device["schema"]))
|
||||||
|
|
||||||
if "localKey" not in device or not device["localKey"]:
|
vac_details = {
|
||||||
_LOGGER.error("Local key missing for vacuum {} ({}) in data from Tuya. Skipping.".format(allvacs[device["devId"]][CONF_NAME], device["devId"]))
|
CONF_ID: item["device"]["id"],
|
||||||
continue
|
CONF_MODEL: item["device"]["product"]["product_code"],
|
||||||
|
CONF_NAME: item["device"]["alias_name"],
|
||||||
allvacs[device["devId"]][CONF_ACCESS_TOKEN] = device["localKey"]
|
CONF_DESCRIPTION: item["device"]["name"],
|
||||||
allvacs[device["devId"]][CONF_LOCATION] = home["groupId"]
|
CONF_MAC: item["device"]["wifi"]["mac"],
|
||||||
self[CONF_VACS][device["devId"]] = allvacs[device["devId"]]
|
CONF_IP_ADDRESS: "",
|
||||||
|
CONF_AUTODISCOVERY: True,
|
||||||
for vacuum_id in allvacs:
|
CONF_ACCESS_TOKEN: device["localKey"],
|
||||||
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))
|
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
|
return response
|
||||||
|
|
||||||
|
|
@ -187,6 +179,7 @@ class CannotConnect(HomeAssistantError):
|
||||||
class InvalidAuth(HomeAssistantError):
|
class InvalidAuth(HomeAssistantError):
|
||||||
"""Error to indicate there is invalid auth."""
|
"""Error to indicate there is invalid auth."""
|
||||||
|
|
||||||
|
|
||||||
class OptionsFlowHandler(config_entries.OptionsFlow):
|
class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
"""Handles options flow for the component."""
|
"""Handles options flow for the component."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -232,12 +232,12 @@ class TuyaAPISession:
|
||||||
|
|
||||||
def list_homes(self):
|
def list_homes(self):
|
||||||
return self._request(action="tuya.m.location.list", version="2.1")
|
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(
|
return self._request(
|
||||||
action="tuya.m.my.group.device.list",
|
action="tuya.m.device.get",
|
||||||
version="1.0",
|
version="1.0",
|
||||||
query_params={"gid": home_id},
|
data={"devId": devId}
|
||||||
)
|
)
|
||||||
|
|
||||||
def getCountryCode(self, region_code):
|
def getCountryCode(self, region_code):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue