Skip to content

Commit a148f10

Browse files
committed
Added installation instructions for Home Assistant
1 parent 72402da commit a148f10

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ Together with zigpy and compatible home automation software (namely Home Assista
99

1010
This zigpy-znp library allows Zigpy to interact with Texas Instruments ZNP (Zigbee Network Processor) coordinator firmware via TI Z-Stack Monitor and Test(MT) APIs using an UART/serial interface. Radio module hardware compatible include but is possibly not limited to Texas Instruments CC13x2 and CC26x2R based chips flashed with Z-Stack 3.x coordinator firmware.
1111

12+
# Installation
13+
Install the Python module within your virtual environment:
14+
15+
```shell
16+
(venv) $ pip install zigpy-znp
17+
```
18+
19+
If you are using Home Assistant, copy `custom_components/custom_zha_radios.py` into your `custom_components` folder and create a new entry in your `configuration.yaml` file:
20+
21+
```yaml
22+
custom_zha_radios:
23+
znp:
24+
module: zigpy_znp.zigbee.application
25+
description: TI CC13x2, CC26x2, and ZZH
26+
```
27+
1228
# Hardware requirements
1329
USB-adapters, GPIO-modules, and development-boards running recent TI Z-Stack releases (i.e. CC13x2 and CC26x2) are supported. Reference hardware for this project includes:
1430
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import importlib
2+
3+
from homeassistant.components.zha.core.const import RadioType
4+
5+
6+
DOMAIN = "custom_zha_radios"
7+
8+
9+
def patch_enum_member(target_enum, name, value):
10+
"""
11+
Don't tell anybody you called this function. Every line is a hack.
12+
"""
13+
14+
member = target_enum._member_type_.__new__(target_enum)
15+
member._name_ = name
16+
member._value_ = value
17+
18+
if not isinstance(value, tuple):
19+
args = (value,)
20+
else:
21+
args = value
22+
23+
target_enum.__init__(member, *args)
24+
25+
target_enum._member_names_.append(name)
26+
target_enum._member_map_[name] = member
27+
target_enum._value2member_map_[value] = member
28+
type.__setattr__(target_enum, name, member)
29+
30+
31+
def setup(hass, config):
32+
"""
33+
Injects modules from `custom_zha_radios` into `zha`. For example:
34+
35+
custom_zha_radios:
36+
znp:
37+
module: zigpy_znp.zigbee.application
38+
description: TI CC13x2, CC26x2, and ZZH
39+
40+
"""
41+
42+
custom_names = list(config[DOMAIN].keys())
43+
original_names = list(RadioType._member_names_)
44+
45+
for name, obj in config[DOMAIN].items():
46+
module = importlib.import_module(obj["module"])
47+
app = module.ControllerApplication
48+
description = obj["description"]
49+
50+
patch_enum_member(RadioType, name, (description, app))
51+
52+
# New keys are moved up top
53+
RadioType._member_names_ = custom_names + original_names
54+
55+
return True

0 commit comments

Comments
 (0)