Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Add web socket server #271

Draft
wants to merge 137 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
a4b5372
Convert dataclasses to pydantic models
dmulcahey Oct 17, 2024
0d60501
clean up base models and add test
dmulcahey Oct 17, 2024
bc27911
make validators shareable
dmulcahey Oct 18, 2024
bcd0215
add validators and serializers for device models
dmulcahey Oct 18, 2024
ba688d2
use hex repr for nwk
dmulcahey Oct 18, 2024
5ec92a1
only use nwk hex repr for json dump
dmulcahey Oct 18, 2024
69083ca
coverage
dmulcahey Oct 18, 2024
bd04640
ensure we can serialize ExtendedDeviceInfo
dmulcahey Oct 19, 2024
ee0aa6a
Add websocket functionality
dmulcahey Oct 19, 2024
2d06af3
restructure, add entity APIs back and remove duplicate models
dmulcahey Oct 20, 2024
f0c0149
fix imports for typing
dmulcahey Oct 21, 2024
cbeab3d
add alarm control panel WS tests
dmulcahey Oct 21, 2024
d556656
move websocket server gateway impl
dmulcahey Oct 23, 2024
6053cb8
rename websocketgateway to websocketservergateway
dmulcahey Oct 23, 2024
5577431
consistent interfaces
dmulcahey Oct 24, 2024
8502399
Combine branches (#268)
dmulcahey Oct 27, 2024
7718220
proper generics
dmulcahey Oct 27, 2024
23864d4
cover apis and tests
dmulcahey Oct 28, 2024
6147906
finish cover api and clean up tests
dmulcahey Oct 28, 2024
82a39a9
add flow sensor
dmulcahey Oct 30, 2024
bec0995
fix type
dmulcahey Oct 30, 2024
8aaee68
enable / disable
dmulcahey Oct 30, 2024
24183ba
use emit instead of another task
dmulcahey Oct 30, 2024
c64b37a
enable / disable
dmulcahey Oct 30, 2024
ecbafb1
commands
dmulcahey Oct 30, 2024
8ffdb5b
select api connected
dmulcahey Oct 30, 2024
63108d7
lock api connected
dmulcahey Oct 30, 2024
4c17f5c
fill in API methods on client entities
dmulcahey Oct 30, 2024
6ef60d5
connect up number APIs
dmulcahey Oct 30, 2024
3cc4c5f
wire up device trackers with tests
dmulcahey Oct 30, 2024
e1d9132
wire up fans with tests
dmulcahey Oct 30, 2024
8644ee8
siren tests
dmulcahey Oct 31, 2024
a1f4369
switch tests
dmulcahey Oct 31, 2024
d02ac5b
remove duplicate tests
dmulcahey Oct 31, 2024
6fcdb32
light fixes
dmulcahey Oct 31, 2024
f92afb6
clean up - leverage actual types
dmulcahey Oct 31, 2024
65aa3bb
expose config for tests
dmulcahey Oct 31, 2024
caf2bb9
actually emit the client side events
dmulcahey Oct 31, 2024
d8bef39
wire up climate api and add tests
dmulcahey Oct 31, 2024
9246f46
property coverage
dmulcahey Oct 31, 2024
67b8a92
property coverage
dmulcahey Oct 31, 2024
bb72207
property coverage
dmulcahey Oct 31, 2024
c73be2a
remove unnecessary code
dmulcahey Oct 31, 2024
87baf8f
device property coverage
dmulcahey Oct 31, 2024
11ab014
fix test
dmulcahey Oct 31, 2024
05bca9c
more device properties
dmulcahey Oct 31, 2024
f5d8f98
better test stability
dmulcahey Oct 31, 2024
4aec1fe
remove unused code
dmulcahey Oct 31, 2024
0c450d2
add missing fields
dmulcahey Oct 31, 2024
7f7328e
wire in group helper
dmulcahey Oct 31, 2024
191c6d3
missing error
dmulcahey Oct 31, 2024
0c33ee5
wire in entity enable / disable
dmulcahey Nov 1, 2024
baa4b37
group entity availability test
dmulcahey Nov 1, 2024
dd221e9
pass remove group through
dmulcahey Nov 1, 2024
e3abb2a
light api and tests
dmulcahey Nov 1, 2024
c0cb33d
add available to states and fix availability, remove cached prop usag…
dmulcahey Nov 1, 2024
e6f583e
another cached prop
dmulcahey Nov 1, 2024
06a69be
wire in group api on client
dmulcahey Nov 1, 2024
06352ec
prop coverage
dmulcahey Nov 2, 2024
a6f70ba
clean up test fixtures
dmulcahey Nov 2, 2024
763e421
split context manager
dmulcahey Nov 2, 2024
432a024
use new fixture
dmulcahey Nov 2, 2024
5675eca
remove unused code
dmulcahey Nov 2, 2024
2a4522f
attempt to address flakiness in tests
dmulcahey Nov 2, 2024
b5a4dbe
update fixture
dmulcahey Nov 2, 2024
8d48623
unused
dmulcahey Nov 2, 2024
77f76b5
property coverage
dmulcahey Nov 2, 2024
e9e21ca
firmware update API
dmulcahey Nov 2, 2024
6bb9af5
some firmware tests
dmulcahey Nov 2, 2024
5c42f44
use correct command
dmulcahey Nov 2, 2024
1381914
property coverage
dmulcahey Nov 2, 2024
175b975
doc string cleanup
dmulcahey Nov 2, 2024
6231414
remove unused fixture and configure looptime
dmulcahey Nov 2, 2024
3af3d45
clean up (server -> gateway)
dmulcahey Nov 2, 2024
529189c
update tests
dmulcahey Nov 2, 2024
95c37a9
fix network and call initialize on client gateway
dmulcahey Nov 3, 2024
b643ca6
increment message ids due to client gateway init calls
dmulcahey Nov 3, 2024
c3185b9
load controller application state at startup
dmulcahey Nov 3, 2024
1cab741
add script to launch web socket server
dmulcahey Nov 3, 2024
e229eaf
Change how client entities are created
dmulcahey Nov 3, 2024
5a306b7
additional props
dmulcahey Nov 3, 2024
ad26649
add prop
dmulcahey Nov 3, 2024
eb16a85
rework client side entity handling
dmulcahey Nov 3, 2024
dee0c32
fix restore external state types
dmulcahey Nov 3, 2024
bc94086
include fields w/ None for a value
dmulcahey Nov 3, 2024
9640355
add empty handler so method exists
dmulcahey Nov 3, 2024
cf21461
match handling in group
dmulcahey Nov 3, 2024
654123c
rework entity handling to match device
dmulcahey Nov 3, 2024
0428aaf
update availability
dmulcahey Nov 3, 2024
2e47fe2
simplify
dmulcahey Nov 3, 2024
49b445e
use class name for client side exact type match
dmulcahey Nov 4, 2024
0b91446
wait_background
dmulcahey Nov 4, 2024
ef3c5be
fix previous state and use model dump instead of __dict__
dmulcahey Nov 4, 2024
a132421
model updates
dmulcahey Nov 4, 2024
e071b9a
sensor tests... finally
dmulcahey Nov 4, 2024
80b8d7e
update serialization data
dmulcahey Nov 4, 2024
afebf7d
debugging flag
dmulcahey Nov 4, 2024
f9ddcdb
deep compare to ignore list orders in values
dmulcahey Nov 4, 2024
bc43cb4
fix siren issue
dmulcahey Nov 4, 2024
6ec1379
update sensor test
dmulcahey Nov 4, 2024
2f321d7
oope
dmulcahey Nov 4, 2024
3e2122f
not all have these
dmulcahey Nov 4, 2024
cabb3d1
omit main files from coverage
dmulcahey Nov 5, 2024
7ceeeff
unused
dmulcahey Nov 5, 2024
c46d89b
property coverage
dmulcahey Nov 5, 2024
b913aa3
sensor property coverage
dmulcahey Nov 5, 2024
a984530
__dict__ -> model_dump()
dmulcahey Nov 5, 2024
b206bf0
coverage
dmulcahey Nov 5, 2024
9328d71
device offline and online events
dmulcahey Nov 6, 2024
9f6a58b
additional test
dmulcahey Nov 6, 2024
f5b7833
fix butchered const after rebase
dmulcahey Nov 6, 2024
fdb5a87
update serialization data from firmware prop change
dmulcahey Nov 6, 2024
b307563
firmware update rebase cleanup
dmulcahey Nov 6, 2024
309393b
use async_from_config in main
dmulcahey Nov 7, 2024
7956145
dynamically create discriminated unions
dmulcahey Nov 7, 2024
84b64be
fix button state
dmulcahey Nov 7, 2024
ad2acc5
missed state here too
dmulcahey Nov 7, 2024
1094059
missed another one
dmulcahey Nov 7, 2024
352d47b
tagged unions for events, commands and responses
dmulcahey Nov 8, 2024
c2b5d04
streamline
dmulcahey Nov 8, 2024
a29306a
clean up
dmulcahey Nov 8, 2024
b765ee9
clean up with constants and exceptions
dmulcahey Nov 8, 2024
777f5e1
missed constant
dmulcahey Nov 8, 2024
b6644c1
add additional events to union
dmulcahey Nov 8, 2024
d7e5e6d
use enums
dmulcahey Nov 9, 2024
64e2d3a
clean up
dmulcahey Nov 9, 2024
cf8af73
client api coverage
dmulcahey Nov 9, 2024
fa321fb
coverage
dmulcahey Nov 9, 2024
eb58559
additional coverage
dmulcahey Nov 9, 2024
c2027f5
test get group by name - add coverage
dmulcahey Nov 9, 2024
7e1ea96
more coverage
dmulcahey Nov 9, 2024
3f2bc57
clean up
dmulcahey Nov 13, 2024
97557d1
pin version
dmulcahey Nov 13, 2024
3ecd25a
avoid imports outside top level and put models in correct module
dmulcahey Nov 14, 2024
bb263b6
clean up
dmulcahey Nov 14, 2024
3686c44
use TypeAlias
dmulcahey Nov 14, 2024
0d26a6a
fix imports
dmulcahey Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
],
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"python.testing.unittestEnabled": false
}
"python.testing.unittestEnabled": false,
"debugpy.debugJustMyCode": false,
}
66 changes: 66 additions & 0 deletions examples/server_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"ws_server_config": {
"host": "localhost",
"port": 8001,
"network_auto_start": false
},
"ws_client_config": {
"host": "localhost",
"port": 8001,
"aiohttp_session": null
},
"zha_config": {
"coordinator_configuration": {
"path": "/dev/cu.wchusbserial971207DO",
"baudrate": 115200,
"flow_control": "hardware",
"radio_type": "ezsp"
},
"quirks_configuration": {
"enabled": true,
"custom_quirks_path": "/Users/davidmulcahey/.homeassistant/quirks"
},
"device_overrides": {},
"light_options": {
"default_light_transition": 0.0,
"enable_enhanced_light_transition": false,
"enable_light_transitioning_flag": true,
"always_prefer_xy_color_mode": true,
"group_members_assume_state": true
},
"device_options": {
"enable_identify_on_join": true,
"consider_unavailable_mains": 7200,
"consider_unavailable_battery": 21600,
"enable_mains_startup_polling": true
},
"alarm_control_panel_options": {
"master_code": "1234",
"failed_tries": 3,
"arm_requires_code": false
}
},
"zigpy_config": {
"startup_energy_scan": false,
"handle_unknown_devices": true,
"source_routing": true,
"max_concurrent_requests": 128,
"ezsp_config": {
"CONFIG_PACKET_BUFFER_COUNT": 255,
"CONFIG_MTORR_FLOW_CONTROL": 1,
"CONFIG_KEY_TABLE_SIZE": 12,
"CONFIG_ROUTE_TABLE_SIZE": 200
},
"ota": {
"otau_directory": "/Users/davidmulcahey/.homeassistant/zigpy_ota",
"inovelli_provider": false,
"thirdreality_provider": true
},
"database_path": "/Users/davidmulcahey/.homeassistant/zigbee.db",
"device": {
"baudrate": 115200,
"flow_control": "hardware",
"path": "/dev/cu.wchusbserial971207DO"
}
}
}
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ dependencies = [
"zha-quirks==0.0.124",
"pyserial==3.5",
"pyserial-asyncio-fast",
"pydantic==2.9.2",
"websockets<14.0",
"aiohttp"
]

[tool.setuptools.packages.find]
Expand Down Expand Up @@ -231,4 +234,7 @@ show_missing = true
exclude_also = [
"if TYPE_CHECKING:",
"raise NotImplementedError",
]
omit =[
"*/__main__.py",
]
10 changes: 10 additions & 0 deletions script/run_websocket_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# Stop on errors
set -e

cd "$(dirname "$0")/.."

source venv/bin/activate

python -m zha.websocket.server --config=./examples/server_config.json
32 changes: 19 additions & 13 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ def get_entity(
if not isinstance(entity, entity_type):
continue

if exact_entity_type is not None and type(entity) is not exact_entity_type:
if (
exact_entity_type is not None
and entity.info_object.class_name != exact_entity_type.__name__
):
continue

if qualifier is not None and qualifier not in entity.info_object.unique_id:
Expand All @@ -262,45 +265,45 @@ async def group_entity_availability_test(
assert entity.state["available"] is True

device_1.on_network = False
await asyncio.sleep(0.1)
await asyncio.sleep(1)
await zha_gateway.async_block_till_done()
assert entity.state["available"] is True

device_2.on_network = False
await asyncio.sleep(0.1)
await asyncio.sleep(1)
await zha_gateway.async_block_till_done()

assert entity.state["available"] is False

device_1.on_network = True
await asyncio.sleep(0.1)
await asyncio.sleep(1)
await zha_gateway.async_block_till_done()
assert entity.state["available"] is True

device_2.on_network = True
await asyncio.sleep(0.1)
await asyncio.sleep(1)
await zha_gateway.async_block_till_done()

assert entity.state["available"] is True

device_1.available = False
await asyncio.sleep(0.1)
device_1.update_available(available=False, on_network=device_1.on_network)
await asyncio.sleep(1)
await zha_gateway.async_block_till_done()
assert entity.state["available"] is True

device_2.available = False
await asyncio.sleep(0.1)
device_2.update_available(available=False, on_network=device_2.on_network)
await asyncio.sleep(1)
await zha_gateway.async_block_till_done()

assert entity.state["available"] is False

device_1.available = True
await asyncio.sleep(0.1)
device_1.update_available(available=True, on_network=device_1.on_network)
await asyncio.sleep(1)
await zha_gateway.async_block_till_done()
assert entity.state["available"] is True

device_2.available = True
await asyncio.sleep(0.1)
device_2.update_available(available=True, on_network=device_2.on_network)
await asyncio.sleep(1)
await zha_gateway.async_block_till_done()

assert entity.state["available"] is True
Expand Down Expand Up @@ -504,6 +507,9 @@ def create_mock_zigpy_device(
descriptor_capability_field=zdo_t.NodeDescriptor.DescriptorCapability.NONE,
)

if isinstance(node_descriptor, bytes):
node_descriptor = zdo_t.NodeDescriptor.deserialize(node_descriptor)[0]

device.node_desc = node_descriptor
device.last_seen = time.time()

Expand Down
Loading