zigpy / bellows

A Python 3 project to implement EZSP for EmberZNet devices
GNU General Public License v3.0
177 stars 86 forks source link

Revert "Remove UART thread (#598)" #604

Closed puddly closed 6 months ago

puddly commented 6 months ago

This reverts commit 1ac01edef70d49dec21694909ddd9e56d5fc07eb.

The UART thread unfortunately is still necessary: even though writes are done outside of the event loop, notifications to read the serial port's file descriptor are not and any event loop slowdown will cause traffic from the radio to the library to effectively be halted.

Example:

2023-12-28 14:05:17.843 DEBUG (MainThread) [serialpy.descriptor_transport] Event loop woke up reader
2023-12-28 14:05:17.843 DEBUG (MainThread) [serialpy.descriptor_transport] Received b"\x07t\xb1\xedT.\x14\xb6R\x95K%\xabU\x920b\xe07t\x121o\x93=\xccf\x8c\xdd\xec;{\x1f~\x17t\xb1\xedT.\x14\xb6R\x95K%\xabU\x923`\xe37t\x121o\x93<\xcck\x8c\xdd]?\xc4}3~'t\xb1\xedT.\x14\xb6R\x95K%\xabU\x922k\xe17t\x121o\x93?\xcch\x8c\xd5w?\x8c\xe1~7t\xb1\xedT.\x14\xb0^\x95K%\xabU\x925c\xe37t\x121k\x93>\xccc\x89\xd9\xd2\x8b\xfe\xe6\xcd\xdex\x8f~Gt\xb1\xedT.\x14\xb6R\x95K%\xabU\x924{\xe37t\x121o\x939\xcck\x8c\xdd]?\xa2}8~\x0ft\xb1\xedT.\x14\xb6R\x95K%\xabU\x920b\xe07t\x121o\x93=\xccf\x8c\xdd\xec;J\xd3~\x1ft\xb1\xedT.\x14\xb6R\x95K%\xabU\x923`\xe37t\x121o\x93<\xcck\x8c\xdd]?\xf5\xdf~/t\xb1\xedT.\x14\xb6R\x95K%\xabU\x922k\xe17t\x121o\x93?\xcch\x8c\xd5w?\xbd-~?t\xb1\xedT.\x14\xb0^\x95K%\xabU\x925c\xe37t\x121k\x93>\xccc\x89\xd9\xd2\x8b\xfe\xe6\xcd\xdeqD~Ot\xb1\xedT.\x14\xb6R\x95K%\xabU\x924{\xe37t\x121o\x939\xcck\x8c\xdd]?\x93\xd4~\x0ft\xb1\xedT.\x14\xb6R\x95K%\xabU\x920b\xe07t\x121o\x93=\xccf\x8c\xdd\xec;J\xd3~\x1ft\xb1\xedT.\x14\xb6R\x95K%\xabU\x923`\xe37t\x121o\x93<\xcck\x8c\xdd]?\xf5\xdf~/t\xb1\xedT.\x14\xb6R\x95K%\xabU\x922k\xe17t\x121o\x93?\xcch\x8c\xd5w?\xbd-~?t\xb1\xedT.\x14\xb0^\x95K%\xabU\x925c\xe37t\x121k\x93>\xccc\x89\xd9\xd2\x8b\xfe\xe6\xcd\xdeqD~Ot\xb1\xedT.\x14\xb6R\x95K%\xabU\x924{\xe37t\x121o\x939\xcck\x8c\xdd]?\x93\xd4~\x0ft\xb1\xedT.\x14\xb6R\x95K%\xabU\x920b\xe07t\x121o\x93=\xccf\x8c\xdd\xec;J\xd3~\x1ft\xb1\xedT.\x14\xb6R\x95K%\xabU\x923`\xe37t\x121o\x93<\xcck\x8c\xdd]?\xf5\xdf~/t\xb1\xedT.\x14\xb6R\x95K%\xabU\x922k\xe17t\x121o\x93?\xcch\x8c\xd5w?\xbd-~?t\xb1\xedT.\x14\xb0^\x95K%\xabU\x925c\xe37t\x121k\x93>\xccc\x89\xd9\xd2\x8b\xfe\xe6\xcd\xdeqD~Ot\xb1\xedT.\x14\xb6R\x95K%\xabU\x924{\xe37t\x121o\x939\xcck\x8c\xdd]?\x93\xd4~\xc2\x02Q\xa8\xbd~"
2023-12-28 14:05:17.843 DEBUG (MainThread) [serialpy.descriptor_transport] Immediately writing b'\x81`Y~'
2023-12-28 14:05:17.844 DEBUG (MainThread) [serialpy.descriptor_transport] Sent 4 of 4 bytes
2023-12-28 14:05:17.844 DEBUG (MainThread) [bellows.ezsp.protocol] Application frame received incomingMessageHandler: [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=2820, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY: 256>, groupId=0, sequence=121), 254, -82, 0xdf10, 255, 255, b'\x18\xc0\n\x05\x05!\x92\x04']
2023-12-28 14:05:17.845 DEBUG (MainThread) [bellows.zigbee.application] Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=260, clusterId=2820, sourceEndpoint=1, destinationEndpoint=1, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY: 256>, groupId=0, sequence=121), 254, -82, 0xdf10, 255, 255, b'\x18\xc0\n\x05\x05!\x92\x04']
2023-12-28 14:05:17.845 DEBUG (MainThread) [zigpy.application] Received a packet: ZigbeePacket(timestamp=datetime.datetime(2023, 12, 28, 20, 5, 17, 845700, tzinfo=datetime.timezone.utc), src=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0xDF10), src_ep=1, dst=AddrModeAddress(addr_mode=<AddrMode.NWK: 2>, address=0x0000), dst_ep=1, source_route=None, extended_timeout=False, tsn=121, profile_id=260, cluster_id=2820, data=Serialized[b'\x18\xc0\n\x05\x05!\x92\x04'], tx_options=<TransmitOptions.NONE: 0>, radius=0, non_member_radius=0, lqi=254, rssi=-82)
2023-12-28 14:05:17.847 DEBUG (MainThread) [zigpy.zcl] [0xDF10:1:0x0b04] Received ZCL frame: b'\x18\xc0\n\x05\x05!\x92\x04'
2023-12-28 14:05:17.847 DEBUG (MainThread) [zigpy.zcl] [0xDF10:1:0x0b04] Decoded ZCL frame header: ZCLHeader(frame_control=FrameControl(frame_type=<FrameType.GLOBAL_COMMAND: 0>, is_manufacturer_specific=0, direction=<Direction.Client_to_Server: 1>, disable_default_response=1, reserved=0, *is_cluster=False, *is_general=True), tsn=192, command_id=10, *direction=<Direction.Client_to_Server: 1>)
2023-12-28 14:05:17.849 DEBUG (MainThread) [zigpy.zcl] [0xDF10:1:0x0b04] Decoded ZCL frame: ElectricalMeasurement:Report_Attributes(attribute_reports=[Attribute(attrid=0x0505, value=TypeValue(type=uint16_t, value=1170))])
2023-12-28 14:05:17.849 DEBUG (MainThread) [zigpy.zcl] [0xDF10:1:0x0b04] Received command 0x0A (TSN 192): Report_Attributes(attribute_reports=[Attribute(attrid=0x0505, value=TypeValue(type=uint16_t, value=1170))])
2023-12-28 14:05:17.850 DEBUG (MainThread) [zigpy.zcl] [0xDF10:1:0x0b04] Attribute report received: rms_voltage=1170
2023-12-28 14:05:17.852 DEBUG (MainThread) [serialpy.descriptor_transport] Immediately writing b'\x82P:~'
2023-12-28 14:05:17.853 DEBUG (MainThread) [serialpy.descriptor_transport] Sent 4 of 4 bytes
...
codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (09b2782) 99.78% compared to head (94e0e6e) 99.81%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #604 +/- ## ========================================== + Coverage 99.78% 99.81% +0.02% ========================================== Files 67 68 +1 Lines 4728 4817 +89 ========================================== + Hits 4718 4808 +90 + Misses 10 9 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.