Compare commits
8 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
f397319070 | |
|
|
7e60ecd2b4 | |
|
|
c687f111eb | |
|
|
b180896a9c | |
|
|
2968d722f8 | |
|
|
cdcad837b7 | |
|
|
2c741fe32e | |
|
|
3dd4a7b0e0 |
|
|
@ -2,6 +2,7 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
create-release:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
{
|
||||
"branches": [
|
||||
"main"
|
||||
"main",
|
||||
{
|
||||
"name": "*",
|
||||
"channel": "beta",
|
||||
"prerelease": true
|
||||
}
|
||||
],
|
||||
"plugins": [
|
||||
[
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
"""Config flow for Eufy Robovac integration."""
|
||||
from __future__ import annotations
|
||||
import json
|
||||
|
||||
import logging
|
||||
from typing import Any, Optional
|
||||
|
|
@ -39,10 +40,17 @@ from homeassistant.const import (
|
|||
CONF_IP_ADDRESS,
|
||||
CONF_DESCRIPTION,
|
||||
CONF_MAC,
|
||||
CONF_LOCATION,
|
||||
CONF_CLIENT_ID,
|
||||
CONF_REGION,
|
||||
CONF_TIME_ZONE,
|
||||
CONF_COUNTRY_CODE,
|
||||
)
|
||||
|
||||
from .countries import (
|
||||
get_phone_code_by_country_code,
|
||||
get_phone_code_by_region,
|
||||
get_region_by_country_code,
|
||||
get_region_by_phone_code,
|
||||
)
|
||||
|
||||
from .const import CONF_AUTODISCOVERY, DOMAIN, CONF_VACS
|
||||
|
|
@ -88,15 +96,41 @@ def get_eufy_vacuums(self):
|
|||
settings_response = response.json()
|
||||
|
||||
self[CONF_CLIENT_ID] = user_response["user_info"]["id"]
|
||||
self[CONF_REGION] = settings_response["setting"]["home_setting"]["tuya_home"][
|
||||
"tuya_region_code"
|
||||
]
|
||||
if (
|
||||
"tuya_home" in settings_response["setting"]["home_setting"]
|
||||
and "tuya_region_code"
|
||||
in settings_response["setting"]["home_setting"]["tuya_home"]
|
||||
):
|
||||
self[CONF_REGION] = settings_response["setting"]["home_setting"]["tuya_home"][
|
||||
"tuya_region_code"
|
||||
]
|
||||
if user_response["user_info"]["phone_code"]:
|
||||
self[CONF_COUNTRY_CODE] = user_response["user_info"]["phone_code"]
|
||||
else:
|
||||
self[CONF_COUNTRY_CODE] = get_phone_code_by_region(self[CONF_REGION])
|
||||
elif user_response["user_info"]["phone_code"]:
|
||||
self[CONF_REGION] = get_region_by_phone_code(
|
||||
user_response["user_info"]["phone_code"]
|
||||
)
|
||||
self[CONF_COUNTRY_CODE] = user_response["user_info"]["phone_code"]
|
||||
elif user_response["user_info"]["country"]:
|
||||
self[CONF_REGION] = get_region_by_country_code(
|
||||
user_response["user_info"]["country"]
|
||||
)
|
||||
self[CONF_COUNTRY_CODE] = get_phone_code_by_country_code(
|
||||
user_response["user_info"]["country"]
|
||||
)
|
||||
else:
|
||||
self[CONF_REGION] = "EU"
|
||||
self[CONF_COUNTRY_CODE] = "44"
|
||||
|
||||
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],
|
||||
phone_code=self[CONF_COUNTRY_CODE],
|
||||
)
|
||||
|
||||
items = device_response["items"]
|
||||
|
|
@ -105,7 +139,6 @@ def get_eufy_vacuums(self):
|
|||
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"],
|
||||
|
|
@ -120,10 +153,11 @@ def get_eufy_vacuums(self):
|
|||
self[CONF_VACS][item["device"]["id"]] = vac_details
|
||||
except:
|
||||
_LOGGER.debug(
|
||||
"Vacuum {} found on Eufy, but not on Tuya. Skipping.".format(
|
||||
"Skipping vacuum {}: found on Eufy but not on Tuya. Eufy details:".format(
|
||||
item["device"]["id"]
|
||||
)
|
||||
)
|
||||
_LOGGER.debug(json.dumps(item["device"], indent=2))
|
||||
|
||||
return response
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,228 @@
|
|||
COUNTRIES = [
|
||||
{"country_code": "AF", "phone_code": "93", "tuya_region": "EU"},
|
||||
{"country_code": "AL", "phone_code": "355", "tuya_region": "EU"},
|
||||
{"country_code": "DZ", "phone_code": "213", "tuya_region": "EU"},
|
||||
{"country_code": "AO", "phone_code": "244", "tuya_region": "EU"},
|
||||
{"country_code": "AR", "phone_code": "54", "tuya_region": "AZ"},
|
||||
{"country_code": "AM", "phone_code": "374", "tuya_region": "EU"},
|
||||
{"country_code": "AU", "phone_code": "61", "tuya_region": "AZ"},
|
||||
{"country_code": "AT", "phone_code": "43", "tuya_region": "EU"},
|
||||
{"country_code": "AZ", "phone_code": "994", "tuya_region": "EU"},
|
||||
{"country_code": "BH", "phone_code": "973", "tuya_region": "EU"},
|
||||
{"country_code": "BD", "phone_code": "880", "tuya_region": "EU"},
|
||||
{"country_code": "BY", "phone_code": "375", "tuya_region": "EU"},
|
||||
{"country_code": "BE", "phone_code": "32", "tuya_region": "EU"},
|
||||
{"country_code": "BZ", "phone_code": "501", "tuya_region": "EU"},
|
||||
{"country_code": "BJ", "phone_code": "229", "tuya_region": "EU"},
|
||||
{"country_code": "BT", "phone_code": "975", "tuya_region": "EU"},
|
||||
{"country_code": "BO", "phone_code": "591", "tuya_region": "AZ"},
|
||||
{"country_code": "BA", "phone_code": "387", "tuya_region": "EU"},
|
||||
{"country_code": "BW", "phone_code": "267", "tuya_region": "EU"},
|
||||
{"country_code": "BR", "phone_code": "55", "tuya_region": "AZ"},
|
||||
{"country_code": "VG", "phone_code": "1284", "tuya_region": "EU"},
|
||||
{"country_code": "BN", "phone_code": "673", "tuya_region": "EU"},
|
||||
{"country_code": "BG", "phone_code": "359", "tuya_region": "EU"},
|
||||
{"country_code": "BF", "phone_code": "226", "tuya_region": "EU"},
|
||||
{"country_code": "BI", "phone_code": "257", "tuya_region": "EU"},
|
||||
{"country_code": "KH", "phone_code": "855", "tuya_region": "EU"},
|
||||
{"country_code": "CM", "phone_code": "237", "tuya_region": "EU"},
|
||||
{"country_code": "US", "phone_code": "1", "tuya_region": "AZ"},
|
||||
{"country_code": "CA", "phone_code": "1", "tuya_region": "AZ"},
|
||||
{"country_code": "CV", "phone_code": "238", "tuya_region": "EU"},
|
||||
{"country_code": "KY", "phone_code": "1345", "tuya_region": "EU"},
|
||||
{"country_code": "CF", "phone_code": "236", "tuya_region": "EU"},
|
||||
{"country_code": "TD", "phone_code": "235", "tuya_region": "EU"},
|
||||
{"country_code": "CL", "phone_code": "56", "tuya_region": "AZ"},
|
||||
{"country_code": "CN", "phone_code": "86", "tuya_region": "AY"},
|
||||
{"country_code": "CO", "phone_code": "57", "tuya_region": "AZ"},
|
||||
{"country_code": "KM", "phone_code": "269", "tuya_region": "EU"},
|
||||
{"country_code": "CG", "phone_code": "242", "tuya_region": "EU"},
|
||||
{"country_code": "CD", "phone_code": "243", "tuya_region": "EU"},
|
||||
{"country_code": "CR", "phone_code": "506", "tuya_region": "EU"},
|
||||
{"country_code": "HR", "phone_code": "385", "tuya_region": "EU"},
|
||||
{"country_code": "CY", "phone_code": "357", "tuya_region": "EU"},
|
||||
{"country_code": "CZ", "phone_code": "420", "tuya_region": "EU"},
|
||||
{"country_code": "DK", "phone_code": "45", "tuya_region": "EU"},
|
||||
{"country_code": "DJ", "phone_code": "253", "tuya_region": "EU"},
|
||||
{"country_code": "DO", "phone_code": "1809", "tuya_region": "EU"},
|
||||
{"country_code": "DO", "phone_code": "1829", "tuya_region": "EU"},
|
||||
{"country_code": "DO", "phone_code": "1849", "tuya_region": "EU"},
|
||||
{"country_code": "EC", "phone_code": "593", "tuya_region": "AZ"},
|
||||
{"country_code": "EG", "phone_code": "20", "tuya_region": "EU"},
|
||||
{"country_code": "SV", "phone_code": "503", "tuya_region": "EU"},
|
||||
{"country_code": "GQ", "phone_code": "240", "tuya_region": "EU"},
|
||||
{"country_code": "ER", "phone_code": "291", "tuya_region": "EU"},
|
||||
{"country_code": "EE", "phone_code": "372", "tuya_region": "EU"},
|
||||
{"country_code": "ET", "phone_code": "251", "tuya_region": "EU"},
|
||||
{"country_code": "FJ", "phone_code": "679", "tuya_region": "EU"},
|
||||
{"country_code": "FI", "phone_code": "358", "tuya_region": "EU"},
|
||||
{"country_code": "FR", "phone_code": "33", "tuya_region": "EU"},
|
||||
{"country_code": "GA", "phone_code": "241", "tuya_region": "EU"},
|
||||
{"country_code": "GM", "phone_code": "220", "tuya_region": "EU"},
|
||||
{"country_code": "GE", "phone_code": "995", "tuya_region": "EU"},
|
||||
{"country_code": "DE", "phone_code": "49", "tuya_region": "EU"},
|
||||
{"country_code": "GH", "phone_code": "233", "tuya_region": "EU"},
|
||||
{"country_code": "GR", "phone_code": "30", "tuya_region": "EU"},
|
||||
{"country_code": "GL", "phone_code": "299", "tuya_region": "EU"},
|
||||
{"country_code": "GT", "phone_code": "502", "tuya_region": "AZ"},
|
||||
{"country_code": "GN", "phone_code": "224", "tuya_region": "EU"},
|
||||
{"country_code": "GY", "phone_code": "592", "tuya_region": "EU"},
|
||||
{"country_code": "HT", "phone_code": "509", "tuya_region": "EU"},
|
||||
{"country_code": "HN", "phone_code": "504", "tuya_region": "EU"},
|
||||
{"country_code": "HK", "phone_code": "852", "tuya_region": "AZ"},
|
||||
{"country_code": "HU", "phone_code": "36", "tuya_region": "EU"},
|
||||
{"country_code": "IS", "phone_code": "354", "tuya_region": "EU"},
|
||||
{"country_code": "IN", "phone_code": "91", "tuya_region": "IN"},
|
||||
{"country_code": "ID", "phone_code": "62", "tuya_region": "AZ"},
|
||||
{"country_code": "IR", "phone_code": "98", "tuya_region": "EU"},
|
||||
{"country_code": "IQ", "phone_code": "964", "tuya_region": "EU"},
|
||||
{"country_code": "IE", "phone_code": "353", "tuya_region": "EU"},
|
||||
{"country_code": "IM", "phone_code": "44", "tuya_region": "EU"},
|
||||
{"country_code": "IL", "phone_code": "972", "tuya_region": "EU"},
|
||||
{"country_code": "IT", "phone_code": "39", "tuya_region": "AZ"},
|
||||
{"country_code": "CI", "phone_code": "225", "tuya_region": "EU"},
|
||||
{"country_code": "JM", "phone_code": "1876", "tuya_region": "EU"},
|
||||
{"country_code": "JP", "phone_code": "81", "tuya_region": "AZ"},
|
||||
{"country_code": "JO", "phone_code": "962", "tuya_region": "EU"},
|
||||
{"country_code": "KZ", "phone_code": "7", "tuya_region": "EU"},
|
||||
{"country_code": "KE", "phone_code": "254", "tuya_region": "EU"},
|
||||
{"country_code": "KR", "phone_code": "82", "tuya_region": "AZ"},
|
||||
{"country_code": "KW", "phone_code": "965", "tuya_region": "EU"},
|
||||
{"country_code": "KG", "phone_code": "996", "tuya_region": "EU"},
|
||||
{"country_code": "LA", "phone_code": "856", "tuya_region": "EU"},
|
||||
{"country_code": "LV", "phone_code": "371", "tuya_region": "EU"},
|
||||
{"country_code": "LB", "phone_code": "961", "tuya_region": "EU"},
|
||||
{"country_code": "LS", "phone_code": "266", "tuya_region": "EU"},
|
||||
{"country_code": "LR", "phone_code": "231", "tuya_region": "EU"},
|
||||
{"country_code": "LY", "phone_code": "218", "tuya_region": "EU"},
|
||||
{"country_code": "LT", "phone_code": "370", "tuya_region": "EU"},
|
||||
{"country_code": "LU", "phone_code": "352", "tuya_region": "EU"},
|
||||
{"country_code": "MO", "phone_code": "853", "tuya_region": "AZ"},
|
||||
{"country_code": "MK", "phone_code": "389", "tuya_region": "EU"},
|
||||
{"country_code": "MG", "phone_code": "261", "tuya_region": "EU"},
|
||||
{"country_code": "MW", "phone_code": "265", "tuya_region": "EU"},
|
||||
{"country_code": "MY", "phone_code": "60", "tuya_region": "AZ"},
|
||||
{"country_code": "MV", "phone_code": "960", "tuya_region": "EU"},
|
||||
{"country_code": "ML", "phone_code": "223", "tuya_region": "EU"},
|
||||
{"country_code": "MT", "phone_code": "356", "tuya_region": "EU"},
|
||||
{"country_code": "MR", "phone_code": "222", "tuya_region": "EU"},
|
||||
{"country_code": "MU", "phone_code": "230", "tuya_region": "EU"},
|
||||
{"country_code": "MX", "phone_code": "52", "tuya_region": "AZ"},
|
||||
{"country_code": "MD", "phone_code": "373", "tuya_region": "EU"},
|
||||
{"country_code": "MC", "phone_code": "377", "tuya_region": "EU"},
|
||||
{"country_code": "MN", "phone_code": "976", "tuya_region": "EU"},
|
||||
{"country_code": "ME", "phone_code": "382", "tuya_region": "EU"},
|
||||
{"country_code": "MA", "phone_code": "212", "tuya_region": "EU"},
|
||||
{"country_code": "MZ", "phone_code": "258", "tuya_region": "EU"},
|
||||
{"country_code": "MM", "phone_code": "95", "tuya_region": "AZ"},
|
||||
{"country_code": "NA", "phone_code": "264", "tuya_region": "EU"},
|
||||
{"country_code": "NP", "phone_code": "977", "tuya_region": "EU"},
|
||||
{"country_code": "NL", "phone_code": "31", "tuya_region": "EU"},
|
||||
{"country_code": "NZ", "phone_code": "64", "tuya_region": "AZ"},
|
||||
{"country_code": "NI", "phone_code": "505", "tuya_region": "AZ"},
|
||||
{"country_code": "NE", "phone_code": "227", "tuya_region": "EU"},
|
||||
{"country_code": "NG", "phone_code": "234", "tuya_region": "EU"},
|
||||
{"country_code": "KP", "phone_code": "850", "tuya_region": "EU"},
|
||||
{"country_code": "NO", "phone_code": "47", "tuya_region": "EU"},
|
||||
{"country_code": "OM", "phone_code": "968", "tuya_region": "EU"},
|
||||
{"country_code": "PK", "phone_code": "92", "tuya_region": "EU"},
|
||||
{"country_code": "PA", "phone_code": "507", "tuya_region": "EU"},
|
||||
{"country_code": "PY", "phone_code": "595", "tuya_region": "AZ"},
|
||||
{"country_code": "PE", "phone_code": "51", "tuya_region": "AZ"},
|
||||
{"country_code": "PH", "phone_code": "63", "tuya_region": "AZ"},
|
||||
{"country_code": "PL", "phone_code": "48", "tuya_region": "EU"},
|
||||
{"country_code": "PF", "phone_code": "689", "tuya_region": "EU"},
|
||||
{"country_code": "PT", "phone_code": "351", "tuya_region": "EU"},
|
||||
{"country_code": "PR", "phone_code": "1787", "tuya_region": "AZ"},
|
||||
{"country_code": "QA", "phone_code": "974", "tuya_region": "EU"},
|
||||
{"country_code": "RE", "phone_code": "262", "tuya_region": "EU"},
|
||||
{"country_code": "RO", "phone_code": "40", "tuya_region": "EU"},
|
||||
{"country_code": "RU", "phone_code": "7", "tuya_region": "EU"},
|
||||
{"country_code": "RW", "phone_code": "250", "tuya_region": "EU"},
|
||||
{"country_code": "SM", "phone_code": "378", "tuya_region": "EU"},
|
||||
{"country_code": "SA", "phone_code": "966", "tuya_region": "EU"},
|
||||
{"country_code": "SN", "phone_code": "221", "tuya_region": "EU"},
|
||||
{"country_code": "RS", "phone_code": "381", "tuya_region": "EU"},
|
||||
{"country_code": "SL", "phone_code": "232", "tuya_region": "EU"},
|
||||
{"country_code": "SG", "phone_code": "65", "tuya_region": "EU"},
|
||||
{"country_code": "SK", "phone_code": "421", "tuya_region": "EU"},
|
||||
{"country_code": "SI", "phone_code": "386", "tuya_region": "EU"},
|
||||
{"country_code": "SO", "phone_code": "252", "tuya_region": "EU"},
|
||||
{"country_code": "ZA", "phone_code": "27", "tuya_region": "EU"},
|
||||
{"country_code": "ES", "phone_code": "34", "tuya_region": "EU"},
|
||||
{"country_code": "LK", "phone_code": "94", "tuya_region": "EU"},
|
||||
{"country_code": "SD", "phone_code": "249", "tuya_region": "EU"},
|
||||
{"country_code": "SR", "phone_code": "597", "tuya_region": "AZ"},
|
||||
{"country_code": "SZ", "phone_code": "268", "tuya_region": "EU"},
|
||||
{"country_code": "SE", "phone_code": "46", "tuya_region": "EU"},
|
||||
{"country_code": "CH", "phone_code": "41", "tuya_region": "EU"},
|
||||
{"country_code": "SY", "phone_code": "963", "tuya_region": "EU"},
|
||||
{"country_code": "TW", "phone_code": "886", "tuya_region": "AZ"},
|
||||
{"country_code": "TJ", "phone_code": "992", "tuya_region": "EU"},
|
||||
{"country_code": "TZ", "phone_code": "255", "tuya_region": "EU"},
|
||||
{"country_code": "TH", "phone_code": "66", "tuya_region": "AZ"},
|
||||
{"country_code": "TG", "phone_code": "228", "tuya_region": "EU"},
|
||||
{"country_code": "TO", "phone_code": "676", "tuya_region": "EU"},
|
||||
{"country_code": "TT", "phone_code": "1868", "tuya_region": "EU"},
|
||||
{"country_code": "TN", "phone_code": "216", "tuya_region": "EU"},
|
||||
{"country_code": "TR", "phone_code": "90", "tuya_region": "EU"},
|
||||
{"country_code": "TM", "phone_code": "993", "tuya_region": "EU"},
|
||||
{"country_code": "VI", "phone_code": "1340", "tuya_region": "EU"},
|
||||
{"country_code": "UG", "phone_code": "256", "tuya_region": "EU"},
|
||||
{"country_code": "UA", "phone_code": "380", "tuya_region": "EU"},
|
||||
{"country_code": "AE", "phone_code": "971", "tuya_region": "EU"},
|
||||
{"country_code": "GB", "phone_code": "44", "tuya_region": "EU"},
|
||||
{"country_code": "UY", "phone_code": "598", "tuya_region": "AZ"},
|
||||
{"country_code": "UZ", "phone_code": "998", "tuya_region": "EU"},
|
||||
{"country_code": "VA", "phone_code": "379", "tuya_region": "EU"},
|
||||
{"country_code": "VE", "phone_code": "58", "tuya_region": "AZ"},
|
||||
{"country_code": "VN", "phone_code": "84", "tuya_region": "AZ"},
|
||||
{"country_code": "YE", "phone_code": "967", "tuya_region": "EU"},
|
||||
{"country_code": "ZR", "phone_code": "243", "tuya_region": "EU"},
|
||||
{"country_code": "ZM", "phone_code": "260", "tuya_region": "EU"},
|
||||
{"country_code": "ZW", "phone_code": "263", "tuya_region": "EU"},
|
||||
{"country_code": "NCL", "phone_code": "687", "tuya_region": "EU"},
|
||||
{"country_code": "MQ", "phone_code": "596", "tuya_region": "EU"},
|
||||
]
|
||||
|
||||
|
||||
def get_region_by_country_code(country_code):
|
||||
country = next(
|
||||
(item for item in COUNTRIES if item["country_code"] == country_code), None
|
||||
)
|
||||
|
||||
if country is None:
|
||||
return "EU"
|
||||
|
||||
return country["tuya_region"]
|
||||
|
||||
|
||||
def get_region_by_phone_code(phone_code):
|
||||
country = next(
|
||||
(item for item in COUNTRIES if item["phone_code"] == phone_code), None
|
||||
)
|
||||
|
||||
if country is None:
|
||||
return "EU"
|
||||
|
||||
return country["tuya_region"]
|
||||
|
||||
|
||||
def get_phone_code_by_region(region):
|
||||
country = next((item for item in COUNTRIES if item["tuya_region"] == region), None)
|
||||
|
||||
if country is None:
|
||||
return "44"
|
||||
|
||||
return country["phone_code"]
|
||||
|
||||
|
||||
def get_phone_code_by_country_code(country_code):
|
||||
country = next(
|
||||
(item for item in COUNTRIES if item["country_code"] == country_code), None
|
||||
)
|
||||
|
||||
if country is None:
|
||||
return "44"
|
||||
|
||||
return country["phone_code"]
|
||||
|
|
@ -46,6 +46,7 @@ import socket
|
|||
import struct
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
from typing import Callable, Coroutine
|
||||
|
||||
from cryptography.hazmat.backends.openssl import backend as openssl_backend
|
||||
|
|
@ -527,7 +528,7 @@ class Message:
|
|||
await self.device._async_send(self)
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data, cipher=None):
|
||||
def from_bytes(cls, device, data, cipher=None):
|
||||
try:
|
||||
prefix, sequence, command, payload_size = struct.unpack_from(
|
||||
MESSAGE_PREFIX_FORMAT, data
|
||||
|
|
@ -584,15 +585,15 @@ class Message:
|
|||
try:
|
||||
payload_text = payload_data.decode("utf8")
|
||||
except UnicodeDecodeError as e:
|
||||
_LOGGER.debug(payload_data.hex())
|
||||
_LOGGER.error(e)
|
||||
device._LOGGER.debug(payload_data.hex())
|
||||
device._LOGGER.error(e)
|
||||
raise MessageDecodeFailed() from e
|
||||
try:
|
||||
payload = json.loads(payload_text)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
# data may be encrypted
|
||||
_LOGGER.debug(payload_data.hex())
|
||||
_LOGGER.error(e)
|
||||
device._LOGGER.debug(payload_data.hex())
|
||||
device._LOGGER.error(e)
|
||||
raise MessageDecodeFailed() from e
|
||||
|
||||
return cls(command, payload, sequence)
|
||||
|
|
@ -614,6 +615,7 @@ class TuyaDevice:
|
|||
version=(3, 3),
|
||||
):
|
||||
"""Initialize the device."""
|
||||
self._LOGGER = _LOGGER.getChild(device_id)
|
||||
self.device_id = device_id
|
||||
self.host = host
|
||||
self.port = port
|
||||
|
|
@ -668,7 +670,7 @@ class TuyaDevice:
|
|||
self.clean_queue()
|
||||
|
||||
if len(self._queue) > 0:
|
||||
_LOGGER.debug(
|
||||
self._LOGGER.debug(
|
||||
"Processing queue. Current length: {}".format(len(self._queue))
|
||||
)
|
||||
try:
|
||||
|
|
@ -679,14 +681,16 @@ class TuyaDevice:
|
|||
self._backoff = False
|
||||
except Exception as e:
|
||||
self._failures += 1
|
||||
_LOGGER.debug("{} failures. Most recent: {}".format(self._failures, e))
|
||||
self._LOGGER.debug(
|
||||
"{} failures. Most recent: {}".format(self._failures, e)
|
||||
)
|
||||
if self._failures > 3:
|
||||
self._backoff = True
|
||||
self._queue_interval = min(
|
||||
INITIAL_BACKOFF * (BACKOFF_MULTIPLIER ** (self._failures - 4)),
|
||||
600,
|
||||
)
|
||||
_LOGGER.warn(
|
||||
self._LOGGER.warn(
|
||||
"{} failures, backing off for {} seconds".format(
|
||||
self._failures, self._queue_interval
|
||||
)
|
||||
|
|
@ -709,7 +713,7 @@ class TuyaDevice:
|
|||
|
||||
sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
|
||||
sock.settimeout(self.timeout)
|
||||
_LOGGER.debug("Connecting to {}".format(self))
|
||||
self._LOGGER.debug("Connecting to {}".format(self))
|
||||
try:
|
||||
sock.connect((self.host, self.port))
|
||||
except (socket.timeout, TimeoutError) as e:
|
||||
|
|
@ -734,7 +738,7 @@ class TuyaDevice:
|
|||
if self._connected is False:
|
||||
return
|
||||
|
||||
_LOGGER.debug("Disconnected from {}".format(self))
|
||||
self._LOGGER.debug("Disconnected from {}".format(self))
|
||||
self._connected = False
|
||||
self.last_pong = 0
|
||||
|
||||
|
|
@ -769,7 +773,7 @@ class TuyaDevice:
|
|||
return
|
||||
|
||||
if self._backoff is True:
|
||||
_LOGGER.debug("Currently in backoff, not adding ping to queue")
|
||||
self._LOGGER.debug("Currently in backoff, not adding ping to queue")
|
||||
else:
|
||||
self.last_ping = time.time()
|
||||
encrypt = False if self.version < (3, 3) else True
|
||||
|
|
@ -801,7 +805,7 @@ class TuyaDevice:
|
|||
and state_message.payload["dps"]
|
||||
):
|
||||
self._dps.update(state_message.payload["dps"])
|
||||
_LOGGER.debug("Received updated state {}: {}".format(self, self._dps))
|
||||
self._LOGGER.debug("Received updated state {}: {}".format(self, self._dps))
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
@ -821,21 +825,23 @@ class TuyaDevice:
|
|||
)
|
||||
await self._response_task
|
||||
response_data = self._response_task.result()
|
||||
message = Message.from_bytes(response_data, self.cipher)
|
||||
message = Message.from_bytes(self, response_data, self.cipher)
|
||||
except Exception as e:
|
||||
if isinstance(e, InvalidMessage):
|
||||
_LOGGER.debug("Invalid message from {}: {}".format(self, e))
|
||||
self._LOGGER.debug("Invalid message from {}: {}".format(self, e))
|
||||
elif isinstance(e, MessageDecodeFailed):
|
||||
_LOGGER.debug("Failed to decrypt message from {}".format(self))
|
||||
self._LOGGER.debug("Failed to decrypt message from {}".format(self))
|
||||
elif isinstance(e, asyncio.IncompleteReadError):
|
||||
if self._connected:
|
||||
_LOGGER.debug("Incomplete read")
|
||||
self._LOGGER.debug("Incomplete read")
|
||||
elif isinstance(e, ConnectionResetError):
|
||||
_LOGGER.debug("Connection reset: {}".format(e))
|
||||
self._LOGGER.debug(
|
||||
"Connection reset: {}\n{}".format(e, traceback.format_exc())
|
||||
)
|
||||
await self.async_disconnect()
|
||||
|
||||
else:
|
||||
_LOGGER.debug("Received message from {}: {}".format(self, message))
|
||||
self._LOGGER.debug("Received message from {}: {}".format(self, message))
|
||||
if message.sequence in self._listeners:
|
||||
sem = self._listeners[message.sequence]
|
||||
if isinstance(sem, asyncio.Semaphore):
|
||||
|
|
@ -850,7 +856,7 @@ class TuyaDevice:
|
|||
asyncio.create_task(self._async_handle_message())
|
||||
|
||||
async def _async_send(self, message, retries=2):
|
||||
_LOGGER.debug("Sending to {}: {}".format(self, message))
|
||||
self._LOGGER.debug("Sending to {}: {}".format(self, message))
|
||||
try:
|
||||
await self.async_connect()
|
||||
self.writer.write(message.bytes())
|
||||
|
|
@ -871,19 +877,19 @@ class TuyaDevice:
|
|||
raise TuyaException("Failed to send data to {}".format(self))
|
||||
|
||||
if isinstance(e, socket.error):
|
||||
_LOGGER.debug(
|
||||
self._LOGGER.debug(
|
||||
"Retrying send due to error. Connection to {} failed: {}".format(
|
||||
self, e
|
||||
)
|
||||
)
|
||||
elif isinstance(e, asyncio.IncompleteReadError):
|
||||
_LOGGER.debug(
|
||||
self._LOGGER.debug(
|
||||
"Retrying send due to error. Incomplete read from: {} : {}. Partial data recieved: {}".format(
|
||||
self, e, e.partial
|
||||
)
|
||||
)
|
||||
else:
|
||||
_LOGGER.debug(
|
||||
self._LOGGER.debug(
|
||||
"Retrying send due to error. Failed to send data to {}".format(self)
|
||||
)
|
||||
await asyncio.sleep(0.25)
|
||||
|
|
|
|||
|
|
@ -90,17 +90,20 @@ class TuyaAPISession:
|
|||
country_code = None
|
||||
session_id = None
|
||||
|
||||
def __init__(self, username, region, timezone):
|
||||
def __init__(self, username, region, timezone, phone_code):
|
||||
self.session = requests.session()
|
||||
self.session.headers = DEFAULT_TUYA_HEADERS.copy()
|
||||
self.default_query_params = DEFAULT_TUYA_QUERY_PARAMS.copy()
|
||||
self.default_query_params["deviceId"] = self.generate_new_device_id()
|
||||
self.username = username
|
||||
self.country_code = self.getCountryCode(region)
|
||||
self.country_code = phone_code
|
||||
self.base_url = {
|
||||
"EU": "https://a1.tuyaeu.com",
|
||||
"AZ": "https://a1.tuyaus.com",
|
||||
"AY": "https://a1.tuyacn.com",
|
||||
}.get(region, "https://a1.tuyaus.com")
|
||||
"IN": "https://a1.tuyain.com",
|
||||
"EU": "https://a1.tuyaeu.com",
|
||||
}.get(region, "https://a1.tuyaeu.com")
|
||||
|
||||
DEFAULT_TUYA_QUERY_PARAMS["timeZoneId"] = timezone
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -232,13 +235,8 @@ class TuyaAPISession:
|
|||
|
||||
def list_homes(self):
|
||||
return self._request(action="tuya.m.location.list", version="2.1")
|
||||
|
||||
|
||||
def get_device(self, devId):
|
||||
return self._request(
|
||||
action="tuya.m.device.get",
|
||||
version="1.0",
|
||||
data={"devId": devId}
|
||||
action="tuya.m.device.get", version="1.0", data={"devId": devId}
|
||||
)
|
||||
|
||||
def getCountryCode(self, region_code):
|
||||
return {"EU": "44", "AY": "86"}.get(region_code, "1")
|
||||
|
|
|
|||
|
|
@ -89,28 +89,16 @@ UPDATE_RETRIES = 3
|
|||
|
||||
|
||||
class TUYA_CODES(StrEnum):
|
||||
MODE = "5"
|
||||
STATE = "15"
|
||||
# FAN_SPEED = "102"
|
||||
FAN_SPEED = "130"
|
||||
BATTERY_LEVEL = "104"
|
||||
STATE = "15"
|
||||
ERROR_CODE = "106"
|
||||
CLEANING_TIME = "109"
|
||||
MODE = "5"
|
||||
FAN_SPEED = "102"
|
||||
CLEANING_AREA = "110"
|
||||
DO_NOT_DISTURB = "107"
|
||||
DO_NOT_DISTURB2 = "139"
|
||||
BOOST_IQ = "118"
|
||||
CLEANING_TIME = "109"
|
||||
AUTO_RETURN = "135"
|
||||
RETURN_HOME = "101" # boolean
|
||||
A_111 = "111" # 65?
|
||||
A_122 = "122" # continue
|
||||
A_131 = "131" # false
|
||||
A_137 = "137" # 0
|
||||
HARDWARE_CODE = "115" # decoded
|
||||
A_112 = "112" # decoded clean record?
|
||||
A_113 = "113" # decoded
|
||||
CLEAN_STATISTIC = "114" # decoded
|
||||
MULTI_MAPS = "117" # decoded
|
||||
DO_NOT_DISTURB = "107"
|
||||
BOOST_IQ = "118"
|
||||
|
||||
|
||||
TUYA_CONSUMABLES_CODES = ["142", "116"]
|
||||
|
|
@ -364,14 +352,7 @@ class RoboVacEntity(StateVacuumEntity):
|
|||
# self.map_data = self.tuyastatus.get("121")
|
||||
# self.erro_msg? = self.tuyastatus.get("124")
|
||||
if self.robovac_supported & RoboVacEntityFeature.CONSUMABLES:
|
||||
_LOGGER.debug("Support Consumables")
|
||||
for CONSUMABLE_CODE in TUYA_CONSUMABLES_CODES:
|
||||
_LOGGER.debug("Consumable code is: {}".format(CONSUMABLE_CODE))
|
||||
_LOGGER.debug(
|
||||
"Consumables value is: {}".format(
|
||||
self.tuyastatus.get(CONSUMABLE_CODE)
|
||||
)
|
||||
)
|
||||
if (
|
||||
CONSUMABLE_CODE in self.tuyastatus
|
||||
and self.tuyastatus.get(CONSUMABLE_CODE) is not None
|
||||
|
|
@ -381,18 +362,10 @@ class RoboVacEntity(StateVacuumEntity):
|
|||
"ascii"
|
||||
)
|
||||
)
|
||||
_LOGGER.debug(
|
||||
"Consumables decoded value is: {}".format(consumables)
|
||||
)
|
||||
if (
|
||||
"consumable" in consumables
|
||||
and "duration" in consumables["consumable"]
|
||||
):
|
||||
_LOGGER.debug(
|
||||
"Consumables encoded value is: {}".format(
|
||||
consumables["consumable"]["duration"]
|
||||
)
|
||||
)
|
||||
self._attr_consumables = consumables["consumable"]["duration"]
|
||||
|
||||
async def async_locate(self, **kwargs):
|
||||
|
|
@ -432,7 +405,7 @@ class RoboVacEntity(StateVacuumEntity):
|
|||
fan_speed = "Boost_IQ"
|
||||
elif fan_speed == "Pure":
|
||||
fan_speed = "Quiet"
|
||||
await self.vacuum.async_set({"130": fan_speed})
|
||||
await self.vacuum.async_set({"102": fan_speed})
|
||||
|
||||
async def async_send_command(
|
||||
self, command: str, params: dict | list | None = None, **kwargs
|
||||
|
|
|
|||
Loading…
Reference in New Issue