def test_on_message_hot(self):
        def on_message(msg):
            assert isinstance(msg, DysonPureHotCoolState)

        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":
            "455"
        })
        device.add_message_listener(on_message)
        msg = Mock()
        payload = open("tests/data/state_hot.json", "r").read()
        msg.payload = Mock()
        msg.payload.decode.return_value = payload
        DysonPureCoolLink.on_message(None, device, msg)
 def test_on_message_without_callback(self):
     userdata = Mock()
     userdata.callback_message = []
     msg = Mock()
     payload = b'{"msg":"CURRENT-STATE","time":' \
               b'"2017-02-19T15:00:18.000Z","mode-reason":"LAPP",' \
               b'"state-reason":"MODE","dial":"OFF","rssi":"-58",' \
               b'"product-state":{"fmod":"AUTO","fnst":"FAN",' \
               b'"fnsp":"AUTO","qtar":"0004","oson":"OFF","rhtm":"ON",' \
               b'"filf":"2159","ercd":"02C0","nmod":"ON","wacd":"NONE"},' \
               b'"scheduler":{"srsc":"cbd0","dstv":"0001","tzid":"0001"}}'
     msg.payload = payload
     DysonPureCoolLink.on_message(None, userdata, msg)
    def test_on_message_sensor(self):
        def on_message(msg):
            assert isinstance(msg, DysonEnvironmentalSensorState)

        userdata = Mock()
        userdata.callback_message = [on_message]
        msg = Mock()
        payload = b'{"msg": "ENVIRONMENTAL-CURRENT-SENSOR-DATA","time":' \
                  b'"2017-06-17T23:05:49.001Z","data": '\
                  b'{"tact": "2967","hact": "0054","pact": "0004",' \
                  b'"vact": "0005","sltm": "0028"}}'
        msg.payload = payload
        DysonPureCoolLink.on_message(None, userdata, msg)
    def test_on_message_with_unknown_message(self):
        def on_message(msg):
            # Should not be called
            assert msg == 0

        userdata = Mock()
        userdata.callback_message = [on_message]
        msg = Mock()
        payload = b'{"msg": "ENVIRONMENTAL-CURRENT-SENSOR-DATAS","time":' \
                  b'"2017-06-17T23:05:49.001Z","data": ' \
                  b'{"tact": "2967","hact": "0054","pact": "0004",' \
                  b'"vact": "0005","sltm": "0028"}}'
        msg.payload = payload
        DysonPureCoolLink.on_message(None, userdata, msg)