Merge branch 'master' into master

This commit is contained in:
rospogrigio
2023-09-16 13:03:45 +02:00
committed by GitHub
11 changed files with 93 additions and 17 deletions

View File

@@ -255,6 +255,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
res = await tuya_api.async_get_access_token()
if res != "ok":
_LOGGER.error("Cloud API connection failed: %s", res)
else:
_LOGGER.info("Cloud API connection succeeded.")
res = await tuya_api.async_get_devices_list()
hass.data[DOMAIN][DATA_CLOUD] = tuya_api

View File

@@ -101,7 +101,10 @@ class TuyaCloudApi:
async def async_get_access_token(self):
"""Obtain a valid access token."""
try:
resp = await self.async_make_request("GET", "/v1.0/token?grant_type=1")
except requests.exceptions.ConnectionError:
return "Request failed, status ConnectionError"
if not resp.ok:
return "Request failed, status " + str(resp.status)

View File

@@ -43,10 +43,10 @@ class TuyaDiscovery(asyncio.DatagramProtocol):
"""Start discovery by listening to broadcasts."""
loop = asyncio.get_running_loop()
listener = loop.create_datagram_endpoint(
lambda: self, local_addr=("0.0.0.0", 6666)
lambda: self, local_addr=("0.0.0.0", 6666), reuse_port=True
)
encrypted_listener = loop.create_datagram_endpoint(
lambda: self, local_addr=("0.0.0.0", 6667)
lambda: self, local_addr=("0.0.0.0", 6667), reuse_port=True
)
self._listeners = await asyncio.gather(listener, encrypted_listener)

View File

@@ -817,7 +817,7 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
Args:
dps([int]): list of dps to update, default=detected&whitelisted
"""
if self.version in [3.2, 3.3]: # 3.2 behaves like 3.3 with type_0d
if self.version in [3.2, 3.3, 3.4]: # 3.2 behaves like 3.3 with type_0d
if dps is None:
if not self.dps_cache:
await self.detect_available_dps()

View File

@@ -198,5 +198,29 @@
}
}
},
"services": {
"reload": {
"name": "Reload",
"description": "Reload localtuya and reconnect to all devices."
},
"set_dp": {
"name": "Set datapoint",
"description": "Change the value of a datapoint (DP)",
"fields": {
"device_id": {
"name": "Device ID",
"description": "Device ID of device to change datapoint value for"
},
"dp": {
"name": "DP",
"description": "Datapoint index"
},
"value": {
"name": "Value",
"description": "New value to set"
}
}
}
},
"title": "LocalTuya"
}

View File

@@ -188,5 +188,29 @@
}
}
},
"services": {
"reload": {
"name": "Reload",
"description": "Reload localtuya and reconnect to all devices."
},
"set_dp": {
"name": "Set datapoint",
"description": "Change the value of a datapoint (DP)",
"fields": {
"device_id": {
"name": "Device ID",
"description": "Device ID of device to change datapoint value for"
},
"dp": {
"name": "DP",
"description": "Datapoint index"
},
"value": {
"name": "Value",
"description": "New value to set"
}
}
}
},
"title": "LocalTuya"
}

View File

@@ -188,5 +188,29 @@
}
}
},
"services": {
"reload": {
"name": "Reload",
"description": "Reload localtuya and reconnect to all devices."
},
"set_dp": {
"name": "Set datapoint",
"description": "Change the value of a datapoint (DP)",
"fields": {
"device_id": {
"name": "Device ID",
"description": "Device ID of device to change datapoint value for"
},
"dp": {
"name": "DP",
"description": "Datapoint index"
},
"value": {
"name": "Value",
"description": "New value to set"
}
}
}
},
"title": "LocalTuya"
}

View File

@@ -1,5 +1,5 @@
[tool.black]
target-version = ["py38", "py39"]
target-version = ["py311"]
include = 'custom_components/localtuya/.*\.py'
# pylint config stolen from Home Assistant

View File

@@ -4,7 +4,7 @@ max-line-length = 120
ignore = E203, W503
[mypy]
python_version = 3.9
python_version = 3.11
ignore_errors = true
follow_imports = silent
ignore_missing_imports = true

View File

@@ -1,12 +1,12 @@
[tox]
skipsdist = true
envlist = py{38,39}, lint, typing
envlist = py{311}, lint, typing
skip_missing_interpreters = True
cs_exclude_words = hass,unvalid
[gh-actions]
python =
3.9: clean, py39, lint, typing
3.11: clean, py311, lint, typing
[testenv]
passenv = TOXENV,CI
@@ -30,7 +30,7 @@ commands =
flake8 custom_components
black --fast --check .
pydocstyle -v custom_components
pylint custom_components/localtuya --rcfile=pylint.rc
# pylint custom_components/localtuya --rcfile=pylint.rc
[testenv:typing]
commands =