Esempio n. 1
0
def test_properties(mqtt_client: MockedMQTT):
    """Test properties of Pure Cool Link."""
    device = DysonPureCoolLink(SERIAL, CREDENTIAL, DEVICE_TYPE)
    device.connect(HOST)

    # Status
    assert device.is_on is False
    assert device.auto_mode is False
    assert device.oscillation is False
    assert device.air_quality_target == AirQualityTarget.DEFAULT
    assert device.filter_life == 1500

    # Environmental
    assert device.particulates == 3
    assert device.volatile_organic_compounds == 4

    new_status = {
        "mode-reason": "LAPP",
        "state-reason": "MODE",
        "product-state": {
            "fmod": ["OFF", "AUTO"],
            "fnst": ["OFF", "FAN"],
            "fnsp": ["0001", "AUTO"],
            "qtar": ["0002", "0001"],
            "oson": ["OFF", "ON"],
            "rhtm": ["OFF", "ON"],
            "filf": ["1500", "1450"],
            "ercd": ["NONE", "NONE"],
            "nmod": ["OFF", "ON"],
            "wacd": ["NONE", "NONE"],
        },
        "scheduler": {"srsc": "8773", "dstv": "0000", "tzid": "0001"},
    }
    mqtt_client.state_change(new_status)
    assert device.is_on is True
    assert device.auto_mode is True
    assert device.oscillation is True
    assert device.air_quality_target == AirQualityTarget.VERY_SENSITIVE
    assert device.filter_life == 1450

    mqtt_client._environmental_data = {
        "data": {
            "tact": "2903",
            "hact": "0030",
            "pact": "0005",
            "vact": "INIT",
            "sltm": "0003",
        }
    }
    device.request_environmental_data()
    assert device.particulates == 5
    assert device.volatile_organic_compounds == ENVIRONMENTAL_INIT
Esempio n. 2
0
 def test_dont_request_state_if_not_connected(self, mocked_connect,
                                              mocked_publish):
     device = DysonPureCoolLink({
         "Active":
         True,
         "Serial":
         "device-id-1",
         "Name":
         "device-1",
         "ScaleUnit":
         "SU01",
         "Version":
         "21.03.08",
         "LocalCredentials":
         "1/aJ5t52WvAfn+z+fjDuef86kQDQPefbQ6/70ZGysII1K"
         "e1i0ZHakFH84DZuxsSQ4KTT2vbCm7uYeTORULKLKQ==",
         "AutoUpdate":
         True,
         "NewVersionAvailable":
         False,
         "ProductType":
         "475"
     })
     network_device = NetworkDevice('device-1', 'host', 1111)
     device.connection_callback(False)
     device._add_network_device(network_device)
     connected = device.connect(None, "192.168.0.2")
     self.assertFalse(connected)
     self.assertEqual(mocked_connect.call_count, 1)
     device.request_current_state()
     self.assertEqual(mocked_publish.call_count, 0)
     device.request_environmental_state()
     self.assertEqual(mocked_publish.call_count, 0)
Esempio n. 3
0
 def test_connect_device_with_config_failed(self, mocked_connect,
                                            mocked_loop_start,
                                            mocked_loop_stop):
     device = DysonPureCoolLink({
         "Active":
         True,
         "Serial":
         "device-id-1",
         "Name":
         "device-1",
         "ScaleUnit":
         "SU01",
         "Version":
         "21.03.08",
         "LocalCredentials":
         "1/aJ5t52WvAfn+z+fjDuef86kQDQPefbQ6/"
         "70ZGysII1Ke1i0ZHakFH84DZuxsSQ4KTT2v"
         "bCm7uYeTORULKLKQ==",
         "AutoUpdate":
         True,
         "NewVersionAvailable":
         False,
         "ProductType":
         "475"
     })
     device.connection_callback(False)
     connected = device.connect("192.168.0.2")
     self.assertFalse(connected)
     self.assertIsNone(device.state)
     self.assertEqual(device.network_device.name, "device-1")
     self.assertEqual(device.network_device.address, "192.168.0.2")
     self.assertEqual(device.network_device.port, 1883)
     self.assertEqual(mocked_connect.call_count, 1)
     self.assertEqual(mocked_loop_start.call_count, 1)
     self.assertEqual(mocked_loop_stop.call_count, 1)