Skip to content

Commit

Permalink
Merge branch 'rospogrigio:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulCavill authored Sep 22, 2023
2 parents c9b63f8 + 180b664 commit 0126e19
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 18 deletions.
7 changes: 4 additions & 3 deletions custom_components/localtuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async def _async_reconnect(now):
_handle_reload,
)

hass.helpers.service.async_register_admin_service(
hass.services.async_register(
DOMAIN, SERVICE_SET_DP, _handle_set_dp, schema=SERVICE_SET_DP_SCHEMA
)

Expand Down Expand Up @@ -255,8 +255,9 @@ 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)
_LOGGER.info("Cloud API connection succeeded.")
res = await tuya_api.async_get_devices_list()
else:
_LOGGER.info("Cloud API connection succeeded.")
res = await tuya_api.async_get_devices_list()
hass.data[DOMAIN][DATA_CLOUD] = tuya_api

async def setup_entities(device_ids):
Expand Down
5 changes: 4 additions & 1 deletion custom_components/localtuya/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ async def async_make_request(self, method, url, body=None, headers={}):

async def async_get_access_token(self):
"""Obtain a valid access token."""
resp = await self.async_make_request("GET", "/v1.0/token?grant_type=1")
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)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/localtuya/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ async def start(self):
"""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)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/localtuya/pytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ async def update_dps(self, dps=None):
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()
Expand Down
8 changes: 4 additions & 4 deletions custom_components/localtuya/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"power_outlet": {
"title": "Add subswitch",
"description": "You are about to add subswitch number `{number}`. If you want to add another, tick `Add another switch` before continuing.",
"description": "You are about to add subswitch number `{number}`. If you want to add another, tick `Add another switch` before continuing.",
"data": {
"id": "ID",
"name": "Name",
Expand Down Expand Up @@ -101,10 +101,10 @@
"fan_speed_min": "minimum fan speed integer",
"fan_speed_max": "maximum fan speed integer",
"fan_speed_ordered_list": "Fan speed modes list (overrides speed min/max)",
"fan_direction":"fan direction dps",
"fan_direction": "fan direction dps",
"fan_direction_forward": "forward dps string",
"fan_direction_reverse": "reverse dps string",
"fan_dps_type": "DP value type",
"fan_dps_type": "DP value type",
"current_temperature_dp": "Current Temperature",
"target_temperature_dp": "Target Temperature",
"temperature_step": "Temperature Step (optional)",
Expand Down Expand Up @@ -136,4 +136,4 @@
}
},
"title": "LocalTuya"
}
}
28 changes: 26 additions & 2 deletions custom_components/localtuya/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"fan_speed_min": "minimum fan speed integer",
"fan_speed_max": "maximum fan speed integer",
"fan_speed_ordered_list": "Fan speed modes list (overrides speed min/max)",
"fan_direction":"fan direction dps",
"fan_direction": "fan direction dps",
"fan_direction_forward": "forward dps string",
"fan_direction_reverse": "reverse dps string",
"fan_dps_type": "DP value type",
Expand Down Expand Up @@ -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"
}
}
24 changes: 24 additions & 0 deletions custom_components/localtuya/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
24 changes: 24 additions & 0 deletions custom_components/localtuya/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.black]
target-version = ["py38", "py39"]
target-version = ["py311"]
include = 'custom_components/localtuya/.*\.py'

# pylint config stolen from Home Assistant
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 =
Expand Down

0 comments on commit 0126e19

Please sign in to comment.