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
5bb739b
Convert dataclasses to pydantic models
dmulcahey Oct 17, 2024
32890f8
clean up base models and add test
dmulcahey Oct 17, 2024
8b1df1c
make validators shareable
dmulcahey Oct 18, 2024
f8df4cd
add validators and serializers for device models
dmulcahey Oct 18, 2024
70e2e46
use hex repr for nwk
dmulcahey Oct 18, 2024
89bc0b0
only use nwk hex repr for json dump
dmulcahey Oct 18, 2024
b349868
coverage
dmulcahey Oct 18, 2024
569c117
ensure we can serialize ExtendedDeviceInfo
dmulcahey Oct 19, 2024
8eb092a
Add websocket functionality
dmulcahey Oct 19, 2024
b924dad
restructure, add entity APIs back and remove duplicate models
dmulcahey Oct 20, 2024
2643036
fix imports for typing
dmulcahey Oct 21, 2024
164b279
add alarm control panel WS tests
dmulcahey Oct 21, 2024
929c79d
move websocket server gateway impl
dmulcahey Oct 23, 2024
177c8df
rename websocketgateway to websocketservergateway
dmulcahey Oct 23, 2024
a988df3
consistent interfaces
dmulcahey Oct 24, 2024
8049619
Combine branches (#268)
dmulcahey Oct 27, 2024
1542856
proper generics
dmulcahey Oct 27, 2024
8784eb5
cover apis and tests
dmulcahey Oct 28, 2024
5cdef28
finish cover api and clean up tests
dmulcahey Oct 28, 2024
ac11f40
add flow sensor
dmulcahey Oct 30, 2024
bc7ed2b
fix type
dmulcahey Oct 30, 2024
114b49a
enable / disable
dmulcahey Oct 30, 2024
963d54f
use emit instead of another task
dmulcahey Oct 30, 2024
e5a6215
enable / disable
dmulcahey Oct 30, 2024
8b4ddc1
commands
dmulcahey Oct 30, 2024
7d7fbdd
select api connected
dmulcahey Oct 30, 2024
7204603
lock api connected
dmulcahey Oct 30, 2024
052e380
fill in API methods on client entities
dmulcahey Oct 30, 2024
f78498a
connect up number APIs
dmulcahey Oct 30, 2024
5ebb495
wire up device trackers with tests
dmulcahey Oct 30, 2024
386cf90
wire up fans with tests
dmulcahey Oct 30, 2024
52c3a06
siren tests
dmulcahey Oct 31, 2024
9634aaa
switch tests
dmulcahey Oct 31, 2024
8704985
remove duplicate tests
dmulcahey Oct 31, 2024
5d4899e
light fixes
dmulcahey Oct 31, 2024
887e84a
clean up - leverage actual types
dmulcahey Oct 31, 2024
7366645
expose config for tests
dmulcahey Oct 31, 2024
f7f4ea6
actually emit the client side events
dmulcahey Oct 31, 2024
90beaf4
wire up climate api and add tests
dmulcahey Oct 31, 2024
6bb55b7
property coverage
dmulcahey Oct 31, 2024
072e459
property coverage
dmulcahey Oct 31, 2024
e7147a7
property coverage
dmulcahey Oct 31, 2024
54a3db4
remove unnecessary code
dmulcahey Oct 31, 2024
e85358b
device property coverage
dmulcahey Oct 31, 2024
608fe3a
fix test
dmulcahey Oct 31, 2024
95abb6b
more device properties
dmulcahey Oct 31, 2024
2c127be
better test stability
dmulcahey Oct 31, 2024
ef62e25
remove unused code
dmulcahey Oct 31, 2024
ab05c30
add missing fields
dmulcahey Oct 31, 2024
9ccc6d8
wire in group helper
dmulcahey Oct 31, 2024
93ae249
missing error
dmulcahey Oct 31, 2024
c7865b6
wire in entity enable / disable
dmulcahey Nov 1, 2024
3a690d2
group entity availability test
dmulcahey Nov 1, 2024
c5ce5eb
pass remove group through
dmulcahey Nov 1, 2024
86057d1
light api and tests
dmulcahey Nov 1, 2024
4816eb1
add available to states and fix availability, remove cached prop usag…
dmulcahey Nov 1, 2024
eb10d66
another cached prop
dmulcahey Nov 1, 2024
319c950
wire in group api on client
dmulcahey Nov 1, 2024
48a0396
prop coverage
dmulcahey Nov 2, 2024
5570048
clean up test fixtures
dmulcahey Nov 2, 2024
39de9c5
split context manager
dmulcahey Nov 2, 2024
70ebd19
use new fixture
dmulcahey Nov 2, 2024
3ab89d3
remove unused code
dmulcahey Nov 2, 2024
f301ece
attempt to address flakiness in tests
dmulcahey Nov 2, 2024
2bfc286
update fixture
dmulcahey Nov 2, 2024
34c4a7f
unused
dmulcahey Nov 2, 2024
0d07228
property coverage
dmulcahey Nov 2, 2024
e8caeaa
firmware update API
dmulcahey Nov 2, 2024
4f5847d
some firmware tests
dmulcahey Nov 2, 2024
5d4ec9a
use correct command
dmulcahey Nov 2, 2024
acd196c
property coverage
dmulcahey Nov 2, 2024
d29b124
doc string cleanup
dmulcahey Nov 2, 2024
b034b46
remove unused fixture and configure looptime
dmulcahey Nov 2, 2024
bfc4249
clean up (server -> gateway)
dmulcahey Nov 2, 2024
dc528a2
update tests
dmulcahey Nov 2, 2024
8116425
fix network and call initialize on client gateway
dmulcahey Nov 3, 2024
673877d
increment message ids due to client gateway init calls
dmulcahey Nov 3, 2024
aab4f73
load controller application state at startup
dmulcahey Nov 3, 2024
40cbfc8
add script to launch web socket server
dmulcahey Nov 3, 2024
da4a2c9
Change how client entities are created
dmulcahey Nov 3, 2024
93a6a47
additional props
dmulcahey Nov 3, 2024
76ac3a1
add prop
dmulcahey Nov 3, 2024
3abe63d
rework client side entity handling
dmulcahey Nov 3, 2024
cc60e9d
fix restore external state types
dmulcahey Nov 3, 2024
88a8051
include fields w/ None for a value
dmulcahey Nov 3, 2024
36217a5
add empty handler so method exists
dmulcahey Nov 3, 2024
9a2aff4
match handling in group
dmulcahey Nov 3, 2024
fc5b85d
rework entity handling to match device
dmulcahey Nov 3, 2024
6be28cf
update availability
dmulcahey Nov 3, 2024
63ea7f7
simplify
dmulcahey Nov 3, 2024
7872c8e
use class name for client side exact type match
dmulcahey Nov 4, 2024
e540110
wait_background
dmulcahey Nov 4, 2024
7a30257
fix previous state and use model dump instead of __dict__
dmulcahey Nov 4, 2024
39206c3
model updates
dmulcahey Nov 4, 2024
9af3f4d
sensor tests... finally
dmulcahey Nov 4, 2024
3f532db
update serialization data
dmulcahey Nov 4, 2024
4b6464d
debugging flag
dmulcahey Nov 4, 2024
f324e4a
deep compare to ignore list orders in values
dmulcahey Nov 4, 2024
b48eff6
fix siren issue
dmulcahey Nov 4, 2024
1000228
update sensor test
dmulcahey Nov 4, 2024
da00a85
oope
dmulcahey Nov 4, 2024
1976232
not all have these
dmulcahey Nov 4, 2024
901cc08
omit main files from coverage
dmulcahey Nov 5, 2024
6798b1a
unused
dmulcahey Nov 5, 2024
f1bfe9f
property coverage
dmulcahey Nov 5, 2024
043fe01
sensor property coverage
dmulcahey Nov 5, 2024
61a61ca
__dict__ -> model_dump()
dmulcahey Nov 5, 2024
4721aa8
coverage
dmulcahey Nov 5, 2024
18f491a
device offline and online events
dmulcahey Nov 6, 2024
e6da7bf
additional test
dmulcahey Nov 6, 2024
0a272c5
fix butchered const after rebase
dmulcahey Nov 6, 2024
3369eda
update serialization data from firmware prop change
dmulcahey Nov 6, 2024
bd61618
firmware update rebase cleanup
dmulcahey Nov 6, 2024
07d6073
use async_from_config in main
dmulcahey Nov 7, 2024
a2cefcb
dynamically create discriminated unions
dmulcahey Nov 7, 2024
e3294ee
fix button state
dmulcahey Nov 7, 2024
b32e374
missed state here too
dmulcahey Nov 7, 2024
fe98675
missed another one
dmulcahey Nov 7, 2024
1230a74
tagged unions for events, commands and responses
dmulcahey Nov 8, 2024
45c80a2
streamline
dmulcahey Nov 8, 2024
a93876a
clean up
dmulcahey Nov 8, 2024
f20fad8
clean up with constants and exceptions
dmulcahey Nov 8, 2024
a601820
missed constant
dmulcahey Nov 8, 2024
a68df48
add additional events to union
dmulcahey Nov 8, 2024
2a236d1
use enums
dmulcahey Nov 9, 2024
77bcf64
clean up
dmulcahey Nov 9, 2024
61494f1
client api coverage
dmulcahey Nov 9, 2024
46cc7ac
coverage
dmulcahey Nov 9, 2024
42ac87c
additional coverage
dmulcahey Nov 9, 2024
d6123e0
test get group by name - add coverage
dmulcahey Nov 9, 2024
9efd17a
more coverage
dmulcahey Nov 9, 2024
1aab0fd
clean up
dmulcahey Nov 13, 2024
9fa0fff
pin version
dmulcahey Nov 13, 2024
cc2819e
avoid imports outside top level and put models in correct module
dmulcahey Nov 14, 2024
d542e49
clean up
dmulcahey Nov 14, 2024
8d7e974
use TypeAlias
dmulcahey Nov 14, 2024
7ea1092
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
Loading