Compare commits

...

3 Commits

Author SHA1 Message Date
Imad
c3f399f46e
Merge dfc99b10f3 into 310029d8ed 2024-12-26 11:31:08 +08:00
Li Shuzhen
310029d8ed
chore: update issue template (#445)
Some checks failed
Tests / check-rule-format (push) Has been cancelled
Validate / validate-hassfest (push) Has been cancelled
Validate / validate-hacs (push) Has been cancelled
Validate / validate-lint (push) Has been cancelled
Validate / validate-setup (push) Has been cancelled
2024-12-26 09:11:18 +08:00
Imad
dfc99b10f3
add robust unit test for MIoTNetwork async monitoring
Added event handlers for network_status and network_info changes, ensuring proper logging and validation of state transitions.
2024-12-18 21:04:15 +01:00
2 changed files with 54 additions and 14 deletions

View File

@ -1,4 +1,4 @@
name: Bug report / 报告问题
name: Bug Report / 报告问题
description: Create a report to help us improve. / 报告问题以帮助我们改进
body:
- type: input
@ -33,12 +33,36 @@ body:
validations:
required: true
- type: input
attributes:
label: Reproduce Time / 问题复现的时间点
description: |
> Year-month-day, 24-hour time.
> 年-月-日24小时制。
placeholder: "2025-01-01 17:00:00"
validations:
required: true
- type: textarea
attributes:
label: Home Assistant Logs / 系统日志
description: |
> Please [set the log level](https://github.com/XiaoMi/ha_xiaomi_home/blob/main/CONTRIBUTING.md#reporting-bugs) to `debug` and try to reproduce the problem.
> [Settings > System > Logs > DOWNLOAD FULL LOG](https://my.home-assistant.io/redirect/logs) > Filter `xiaomi_home`
> If you are concerned about privacy, you can send the log to ha_xiaomi_home@xiaomi.com . The mail body should include the link to this issue.
> 请将[日志级别设置](https://github.com/XiaoMi/ha_xiaomi_home/blob/main/doc/CONTRIBUTING_zh.md#%E6%88%91%E5%8F%AF%E4%BB%A5%E5%A6%82%E4%BD%95%E8%B4%A1%E7%8C%AE)为 `debug` 并尝试复现问题。
> [设置 > 系统 > 日志 > 下载完整日志](https://my.home-assistant.io/redirect/logs) > 筛选 `xiaomi_home`
> 如果您担心隐私问题,可将日志发送至 ha_xiaomi_home@xiaomi.com ,邮件正文附上此问题的链接。
- type: input
attributes:
label: Log Timezone / 日志时区
description: |
> The [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) of the timestamp in the log.
> 日志所用时间戳的[时区](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)。
placeholder: "Asia/Shanghai"
validations:
required: true
- type: input
attributes:

View File

@ -5,23 +5,39 @@ import asyncio
# pylint: disable=import-outside-toplevel, unused-argument
@pytest.mark.asyncio
async def test_network_monitor_loop_async():
"""
Test asynchronous network monitoring logic of MIoTNetwork.
"""
from miot.miot_network import MIoTNetwork, InterfaceStatus, NetworkInfo
# Initialize MIoTNetwork instance
miot_net = MIoTNetwork()
async def on_network_status_changed(status: bool):
print(f'on_network_status_changed, {status}')
miot_net.sub_network_status(key='test', handler=on_network_status_changed)
# Define handlers for network events
async def handle_network_status_change(status: bool):
print(f"Network status changed: {status}")
async def on_network_info_changed(
status: InterfaceStatus, info: NetworkInfo):
print(f'on_network_info_changed, {status}, {info}')
miot_net.sub_network_info(key='test', handler=on_network_info_changed)
async def handle_network_info_change(
status: InterfaceStatus, info: NetworkInfo
):
print(f"Network info changed: {status}, {info}")
await miot_net.init_async(3)
await asyncio.sleep(3)
print(f'net status: {miot_net.network_status}')
print(f'net info: {miot_net.network_info}')
await miot_net.deinit_async()
# Subscribe handlers to network events
miot_net.sub_network_status(key="test", handler=handle_network_status_change)
miot_net.sub_network_info(key="test", handler=handle_network_info_change)
# Test the network monitoring functionality
try:
await miot_net.init_async(timeout=3)
await asyncio.sleep(3)
# Log current network state
print(f"Network Status: {miot_net.network_status}")
print(f"Network Info: {miot_net.network_info}")
finally:
# Ensure proper cleanup
await miot_net.deinit_async()