@@ -2842,3 +2842,103 @@ def test_air_purifier_with_empty_data() -> None:
28422842 rssi = - 97 ,
28432843 active = True ,
28442844 )
2845+
2846+
2847+ def test_hub3_active () -> None :
2848+ """Test parsing hub3 with active data."""
2849+ ble_device = generate_ble_device ("aa:bb:cc:dd:ee:ff" , "any" )
2850+ adv_data = generate_advertisement_data (
2851+ manufacturer_data = {2409 : b"\xb0 \xe9 \xfe n^)\x00 \xff h&\xd6 d\x83 \x03 \x99 4\x80 " },
2852+ service_data = {
2853+ "0000fd3d-0000-1000-8000-00805f9b34fb" : b"\x00 \x00 d\x00 \x10 \xb9 @"
2854+ },
2855+ rssi = - 97 ,
2856+ )
2857+ result = parse_advertisement_data (ble_device , adv_data )
2858+ assert result == SwitchBotAdvertisement (
2859+ address = "aa:bb:cc:dd:ee:ff" ,
2860+ data = {
2861+ "rawAdvData" : b"\x00 \x00 d\x00 \x10 \xb9 @" ,
2862+ "data" : {
2863+ "sequence_number" : 0 ,
2864+ "network_state" : 2 ,
2865+ "sensor_inserted" : True ,
2866+ "lightLevel" : 3 ,
2867+ "illuminance" : 90 ,
2868+ "temperature_alarm" : False ,
2869+ "humidity_alarm" : False ,
2870+ "temp" : {"c" : 25.3 , "f" : 77.5 },
2871+ "temperature" : 25.3 ,
2872+ "humidity" : 52 ,
2873+ "motion_detected" : True ,
2874+ },
2875+ "isEncrypted" : False ,
2876+ "model" : b"\x00 \x10 \xb9 @" ,
2877+ "modelFriendlyName" : "Hub3" ,
2878+ "modelName" : SwitchbotModel .HUB3 ,
2879+ },
2880+ device = ble_device ,
2881+ rssi = - 97 ,
2882+ active = True ,
2883+ )
2884+
2885+
2886+ def test_hub3_passive () -> None :
2887+ """Test parsing hub3 with passive data."""
2888+ ble_device = generate_ble_device ("aa:bb:cc:dd:ee:ff" , "any" )
2889+ adv_data = generate_advertisement_data (
2890+ manufacturer_data = {2409 : b"\xb0 \xe9 \xfe n^)\x00 \xff h&\xd6 d\x83 \x03 \x99 4\x80 " },
2891+ rssi = - 97 ,
2892+ )
2893+ result = parse_advertisement_data (ble_device , adv_data , SwitchbotModel .HUB3 )
2894+ assert result == SwitchBotAdvertisement (
2895+ address = "aa:bb:cc:dd:ee:ff" ,
2896+ data = {
2897+ "rawAdvData" : None ,
2898+ "data" : {
2899+ "sequence_number" : 0 ,
2900+ "network_state" : 2 ,
2901+ "sensor_inserted" : True ,
2902+ "lightLevel" : 3 ,
2903+ "illuminance" : 90 ,
2904+ "temperature_alarm" : False ,
2905+ "humidity_alarm" : False ,
2906+ "temp" : {"c" : 25.3 , "f" : 77.5 },
2907+ "temperature" : 25.3 ,
2908+ "humidity" : 52 ,
2909+ "motion_detected" : True ,
2910+ },
2911+ "isEncrypted" : False ,
2912+ "model" : b"\x00 \x10 \xb9 @" ,
2913+ "modelFriendlyName" : "Hub3" ,
2914+ "modelName" : SwitchbotModel .HUB3 ,
2915+ },
2916+ device = ble_device ,
2917+ rssi = - 97 ,
2918+ active = False ,
2919+ )
2920+
2921+
2922+ def test_hub3_with_empty_data () -> None :
2923+ """Test parsing hub3 with empty data."""
2924+ ble_device = generate_ble_device ("aa:bb:cc:dd:ee:ff" , "any" )
2925+ adv_data = generate_advertisement_data (
2926+ manufacturer_data = {2409 : None },
2927+ service_data = {
2928+ "0000fd3d-0000-1000-8000-00805f9b34fb" : b"\x00 \x00 d\x00 \x10 \xb9 @"
2929+ },
2930+ rssi = - 97 ,
2931+ )
2932+ result = parse_advertisement_data (ble_device , adv_data )
2933+ assert result == SwitchBotAdvertisement (
2934+ address = "aa:bb:cc:dd:ee:ff" ,
2935+ data = {
2936+ "rawAdvData" : b"\x00 \x00 d\x00 \x10 \xb9 @" ,
2937+ "data" : {},
2938+ "isEncrypted" : False ,
2939+ "model" : b"\x00 \x10 \xb9 @" ,
2940+ },
2941+ device = ble_device ,
2942+ rssi = - 97 ,
2943+ active = True ,
2944+ )
0 commit comments