Exemplo n.º 1
0
 def test_convert_state_value_integer_sat(self):
     self.assertEqual(0, convert_state_value_to_percent('sat', 0),
                      "should convert 0 and sat")
     self.assertEqual(100, convert_state_value_to_percent('sat', 255),
                      "should convert 255 and sat")
     self.assertEqual(50, convert_state_value_to_percent('sat', 255 / 2),
                      "should convert 255/2 and sat")
     self.assertEqual(44, convert_state_value_to_percent('sat', 112),
                      "Should convert 112 and sat to")
Exemplo n.º 2
0
 def test_convert_state_value_integer_ct(self):
     self.assertEqual(0, convert_state_value_to_percent('ct', 0),
                      "should convert 0 and ct")
     self.assertEqual(28, convert_state_value_to_percent('ct', 255),
                      "should convert 255 and ct")
     self.assertEqual(100,
                      convert_state_value_to_percent('ct', global_ct_max),
                      "should convert ct_max and ct")
     self.assertEqual(0,
                      convert_state_value_to_percent('ct', global_ct_min),
                      "Should convert ct_min and ct")
Exemplo n.º 3
0
def on_message_ws(ws, message):
    logging.debug("on_message_ws: {}".format(str(message)))
    json_payload = json.loads(message)
    item_type = json_payload["r"]
    if item_type in ['scenes']:
        return
    item_id = json_payload["id"]
    item_name = utils.idName[item_type].get(item_id, None)
    if item_name is None:
        return
    _state = json_payload["state"]
    logging.debug(
        "id: {}, name: {}, topic: deconz/status/{}/{} - state: {}".format(
            item_id, item_name, item_type, item_name, _state))
    for key in _state:
        utils.mqtt_client.publish(
            item_type, item_name,
            conversion.convert_state_value_to_percent(key, _state[key]), key)
Exemplo n.º 4
0
 def test_convert_value_on_off_to_percent(self):
     for i in ['on', 'reachable', 'status', 'any_on', 'all_on']:
         self.assertEqual("OFF", convert_state_value_to_percent(i, False))
         self.assertEqual("OFF", convert_state_value_to_percent(i, 'False'))
         self.assertEqual("ON", convert_state_value_to_percent(i, True))
         self.assertEqual("ON", convert_state_value_to_percent(i, 'True'))