Skip to content

Commit

Permalink
Merge branch 'release/0.0.72'
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Apr 11, 2022
2 parents 1cb1d7f + 18f3aad commit 00bdde2
Show file tree
Hide file tree
Showing 25 changed files with 352 additions and 149 deletions.
50 changes: 1 addition & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ The second part is the event data. You only need to supply enough of the event d

If you look at another example for the same device:

`(SHORT_PRESS, DIM_UP): {COMMAND: COMMAND_STEP, CLUSTER_ID: 8, ENDPOINT_ID: 1, ARGS: [0, 30, 9],}`
`(SHORT_PRESS, DIM_UP): {COMMAND: COMMAND_STEP, CLUSTER_ID: 8, ENDPOINT_ID: 1, PARAMS: {'step_mode': 0},}`

You can see a pattern that illustrates how to match a more complex event. In this case the step command is used for the dim up and dim down buttons so we need to match more of the event data to uniquely match the event.

Expand Down Expand Up @@ -535,54 +535,6 @@ def test_ts0121_signature(assert_signature_matches_quirk):
assert_signature_matches_quirk(zhaquirks.tuya.ts0121_plug.Plug, signature)
```

# Testing new releases

Testing a new release of the zha-quirks package before it is released in Home Assistant.

If you are using Supervised Home Assistant (formerly known as the Hassio/Hass.io distro):

- Add <https://github.com/home-assistant/hassio-addons-development> as "add-on" repository
- Install "Custom deps deployment" addon
- Update config like:

```yml
pypi:
- zha-quirks==0.0.38
apk: []
```

where 0.0.38 is the new version

- Start the addon

If you are instead using some custom python installation of Home Assistant then do this:

- Activate your python virtual env
- Update package with `pip`

```bash
pip install zha-quirks==0.0.38
```

# Testing quirks in development in docker based install

If you are using Supervised Home Assistant (formerly known as the Hassio/Hass.io distro) you will need to get access to the home-assistant docker container. Directions below are given for using the portainer add-on to do this, there are other methods as well not covered here.

- Install the portainer add-on (<https://github.com/hassio-addons/addon-portainer>) from Home Assistant Community Add-ons.
- Follow the add-on documentation to un-hide the home-assistant container (<https://github.com/hassio-addons/addon-portainer/blob/master/portainer/DOCS.md>)
- Stage the update quirk in a directory within your config directory
- Use portainer to access a console in the home-assistant container:

<img src="https://user-images.githubusercontent.com/11084412/88719260-fdfa7700-d0f0-11ea-8791-88ed3e26915d.png" width=400 >

- Access the quirks directory
- on HA > 0.113: /usr/local/lib/python3.8/site-packages/zhaquirks/
- on HA < 0.113: /usr/local/lib/python3.7/site-packages/zhaquirks/
- Copy updated/new quirk to zhaquirks directory: `cp -a /config/temp/NEW_QUIRK ./`
- Remove the **pycache** folder so it is regenerated `rm -rf ./__pycache__/`
- Close out the console and restart HA.
- Note: The added/update quirk will not survive a HA version update.

# Thanks

- Special thanks to damarco for the majority of the device tracker code
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import find_packages, setup

VERSION = "0.0.71"
VERSION = "0.0.72"


setup(
Expand All @@ -20,6 +20,6 @@
keywords="zha quirks homeassistant hass",
packages=find_packages(exclude=["tests"]),
python_requires=">=3",
install_requires=["zigpy>=0.44.1"],
install_requires=["zigpy>=0.44.2"],
tests_require=["pytest"],
)
61 changes: 61 additions & 0 deletions tests/test_quirks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
import zhaquirks
import zhaquirks.bosch.motion
from zhaquirks.const import (
ARGS,
COMMAND,
COMMAND_MOVE,
COMMAND_MOVE_COLOR_TEMP,
COMMAND_MOVE_ON_OFF,
COMMAND_MOVE_SATURATION,
COMMAND_MOVE_TO_LEVEL_ON_OFF,
COMMAND_MOVE_TO_SATURATION,
COMMAND_STEP,
COMMAND_STEP_COLOR_TEMP,
COMMAND_STEP_HUE,
COMMAND_STEP_ON_OFF,
COMMAND_STEP_SATURATION,
COMMAND_STOP,
COMMAND_STOP_ON_OFF,
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
Expand All @@ -26,6 +41,7 @@
MODELS_INFO,
NODE_DESCRIPTOR,
OUTPUT_CLUSTERS,
PARAMS,
PROFILE_ID,
SKIP_CONFIGURATION,
)
Expand Down Expand Up @@ -517,3 +533,48 @@ def test_no_module_level_device_automation_triggers(module_name: str) -> None:

mod = importlib.import_module(module_name)
assert not hasattr(mod, "device_automation_triggers")


@pytest.mark.parametrize("quirk", ALL_QUIRK_CLASSES)
def test_migrated_lighting_automation_triggers(quirk: CustomDevice) -> None:
"""Ensure quirks with lighting or level control clusters are using PARAMS."""

if not hasattr(quirk, "device_automation_triggers"):
return

for trigger, event in quirk.device_automation_triggers.items():
if COMMAND not in event:
continue

command = event[COMMAND]

# We only consider lighting commands for now
if command in (
COMMAND_MOVE_SATURATION,
COMMAND_MOVE_TO_SATURATION,
COMMAND_MOVE_COLOR_TEMP,
COMMAND_STEP_HUE,
COMMAND_STEP_SATURATION,
COMMAND_STEP_COLOR_TEMP,
):
cluster = zcl.clusters.lighting.Color
elif command in (
COMMAND_MOVE,
COMMAND_MOVE_ON_OFF,
COMMAND_STEP,
COMMAND_STEP_ON_OFF,
COMMAND_STOP,
COMMAND_STOP_ON_OFF,
COMMAND_MOVE_TO_LEVEL_ON_OFF,
):
cluster = zcl.clusters.general.LevelControl
else:
continue

if ARGS in event:
raise ValueError(f"ARGS should be migrated to PARAMS: {command!r}")
elif PARAMS not in event:
continue

schema = cluster.commands_by_name[command].schema
schema(**event[PARAMS])
12 changes: 12 additions & 0 deletions tests/test_tuya_mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,15 @@ async def test_tuya_mcu_classes():
mcu_version = TuyaMCUCluster.MCUVersion()
assert mcu_version
assert not mcu_version.version

# test TuyaClusterData.manufacturer values
t_c_d = TuyaClusterData(manufacturer=foundation.ZCLHeader.NO_MANUFACTURER_ID)
assert t_c_d.manufacturer == -1
t_c_d = TuyaClusterData(manufacturer=4619)
assert t_c_d.manufacturer == 4619
t_c_d = TuyaClusterData(manufacturer="4098")
assert t_c_d.manufacturer == 4098
with pytest.raises(ValueError):
TuyaClusterData(manufacturer="xiaomi")
with pytest.raises(ValueError):
TuyaClusterData(manufacturer=b"")
4 changes: 2 additions & 2 deletions zhaquirks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
MODELS_INFO,
MOTION_EVENT,
NODE_DESCRIPTOR,
OCCUPANCY_EVENT,
OCCUPANCY_STATE,
OFF,
ON,
OUTPUT_CLUSTERS,
Expand All @@ -42,8 +44,6 @@
)

_LOGGER = logging.getLogger(__name__)
OCCUPANCY_STATE = 0
OCCUPANCY_EVENT = "occupancy_event"


class Bus(ListenableMixin):
Expand Down
29 changes: 21 additions & 8 deletions zhaquirks/adeo/color_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PARAMS,
PROFILE_ID,
SHORT_PRESS,
TURN_OFF,
Expand Down Expand Up @@ -188,49 +189,61 @@ def __init__(self, *args, **kwargs):
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8, # LevelControl.cluster_id
ENDPOINT_ID: 1,
ARGS: [0, 26, 5],
PARAMS: {"step_mode": 0, "step_size": 26, "transition_time": 5},
},
(SHORT_PRESS, DIM_DOWN): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8, # LevelControl.cluster_id
ENDPOINT_ID: 1,
ARGS: [1, 26, 5],
PARAMS: {"step_mode": 1, "step_size": 26, "transition_time": 5},
},
(SHORT_PRESS, COLOR_UP): {
COMMAND: COMMAND_STEP_COLOR_TEMP,
CLUSTER_ID: 768, # Color.cluster_id
ENDPOINT_ID: 1,
ARGS: [3, 22, 5, 153, 370],
PARAMS: {
"step_mode": 3,
"step_size": 22,
"transition_time": 5,
"color_temp_min_mireds": 153,
"color_temp_max_mireds": 370,
},
},
(SHORT_PRESS, COLOR_DOWN): {
COMMAND: COMMAND_STEP_COLOR_TEMP,
CLUSTER_ID: 768, # Color.cluster_id
ENDPOINT_ID: 1,
ARGS: [1, 22, 5, 153, 370],
PARAMS: {
"step_mode": 1,
"step_size": 22,
"transition_time": 5,
"color_temp_min_mireds": 153,
"color_temp_max_mireds": 370,
},
},
(SHORT_PRESS, SATURATION_UP): {
COMMAND: COMMAND_STEP_SATURATION,
CLUSTER_ID: 768, # Color.cluster_id
ENDPOINT_ID: 1,
ARGS: [1, 26, 5],
PARAMS: {"step_mode": 1, "step_size": 26, "transition_time": 5},
},
(SHORT_PRESS, SATURATION_DOWN): {
COMMAND: COMMAND_STEP_SATURATION,
CLUSTER_ID: 768, # Color.cluster_id
ENDPOINT_ID: 1,
ARGS: [3, 26, 5],
PARAMS: {"step_mode": 3, "step_size": 26, "transition_time": 5},
},
(SHORT_PRESS, HUE_LEFT): {
COMMAND: COMMAND_STEP_HUE,
CLUSTER_ID: 768, # Color.cluster_id
ENDPOINT_ID: 1,
ARGS: [3, 22, 5],
PARAMS: {"step_mode": 3, "step_size": 22, "transition_time": 5},
},
(SHORT_PRESS, HUE_RIGHT): {
COMMAND: COMMAND_STEP_HUE,
CLUSTER_ID: 768, # Color.cluster_id
ENDPOINT_ID: 1,
ARGS: [1, 22, 5],
PARAMS: {"step_mode": 1, "step_size": 22, "transition_time": 5},
},
(SHORT_PRESS, BUTTON_1): {
COMMAND: "view",
Expand Down
6 changes: 3 additions & 3 deletions zhaquirks/aduro/adurolightncc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from zigpy.zcl.clusters.lightlink import LightLink

from zhaquirks.const import (
ARGS,
CLUSTER_ID,
COMMAND,
COMMAND_OFF,
Expand All @@ -20,6 +19,7 @@
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PARAMS,
PROFILE_ID,
SHORT_PRESS,
TURN_OFF,
Expand Down Expand Up @@ -91,12 +91,12 @@ class AdurolightNCC(CustomDevice):
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [0, 16, 9],
PARAMS: {"step_mode": 0, "step_size": 16, "transition_time": 9},
},
(SHORT_PRESS, DIM_DOWN): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [1, 16, 9],
PARAMS: {"step_mode": 1, "step_size": 16, "transition_time": 9},
},
}
41 changes: 33 additions & 8 deletions zhaquirks/aurora/aurora_dimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
LEFT,
MODELS_INFO,
OUTPUT_CLUSTERS,
PARAMS,
PROFILE_ID,
RIGHT,
SHORT_PRESS,
Expand Down Expand Up @@ -177,49 +178,73 @@ class WallSwitchColorCluster(EventableCluster, Color):
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [0, 26, 3],
PARAMS: {"step_mode": 0, "step_size": 26, "transition_time": 3},
},
(DIM_DOWN, RIGHT): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 1,
ARGS: [1, 26, 3],
PARAMS: {"step_mode": 1, "step_size": 26, "transition_time": 3},
},
(COLOR_UP, RIGHT): {
COMMAND: COMMAND_STEP_COLOR_TEMP,
CLUSTER_ID: 768,
ENDPOINT_ID: 1,
ARGS: [3, 47, 3, 153, 454],
PARAMS: {
"step_mode": 3,
"step_size": 47,
"transition_time": 3,
"color_temp_min_mireds": 153,
"color_temp_max_mireds": 454,
},
},
(COLOR_DOWN, RIGHT): {
COMMAND: COMMAND_STEP_COLOR_TEMP,
CLUSTER_ID: 768,
ENDPOINT_ID: 1,
ARGS: [1, 47, 3, 153, 454],
PARAMS: {
"step_mode": 1,
"step_size": 47,
"transition_time": 3,
"color_temp_min_mireds": 153,
"color_temp_max_mireds": 454,
},
},
(DIM_UP, LEFT): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 2,
ARGS: [0, 26, 3],
PARAMS: {"step_mode": 0, "step_size": 26, "transition_time": 3},
},
(DIM_DOWN, LEFT): {
COMMAND: COMMAND_STEP,
CLUSTER_ID: 8,
ENDPOINT_ID: 2,
ARGS: [1, 26, 3],
PARAMS: {"step_mode": 1, "step_size": 26, "transition_time": 3},
},
(COLOR_UP, LEFT): {
COMMAND: COMMAND_STEP_COLOR_TEMP,
CLUSTER_ID: 768,
ENDPOINT_ID: 1,
ARGS: [3, 47, 3, 153, 454],
PARAMS: {
"step_mode": 3,
"step_size": 47,
"transition_time": 3,
"color_temp_min_mireds": 153,
"color_temp_max_mireds": 454,
},
},
(COLOR_DOWN, LEFT): {
COMMAND: COMMAND_STEP_COLOR_TEMP,
CLUSTER_ID: 768,
ENDPOINT_ID: 1,
ARGS: [1, 47, 3, 153, 454],
PARAMS: {
"step_mode": 1,
"step_size": 47,
"transition_time": 3,
"color_temp_min_mireds": 153,
"color_temp_max_mireds": 454,
},
},
(SHORT_PRESS, RIGHT): {
CLUSTER_ID: 6,
Expand Down
Loading

0 comments on commit 00bdde2

Please sign in to comment.