Esempio n. 1
0
 def test_21_CreateJson(self):
     """ Create a JSON object for Location.
     """
     l_location = self.m_api.read_location_xml(self.m_pyhouse_obj)
     l_json = encode_json(l_location)
     l_obj = decode_json_unicode(l_json)
     # print(PrettyFormatAny.form(l_obj, 'JSON', 80))
     self.assertEqual(l_obj['Street'], TESTING_LOCATION_STREET)
     self.assertEqual(l_obj['City'], TESTING_LOCATION_CITY)
Esempio n. 2
0
 def test_21_CreateJson(self):
     """ Create a JSON object for Location.
     """
     l_location = self.m_api.read_location_xml(self.m_pyhouse_obj)
     l_json = encode_json(l_location)
     l_obj = decode_json_unicode(l_json)
     # print(PrettyFormatAny.form(l_obj, 'JSON', 80))
     self.assertEqual(l_obj['Street'], TESTING_LOCATION_STREET)
     self.assertEqual(l_obj['City'], TESTING_LOCATION_CITY)
Esempio n. 3
0
    def MqttDispatch(self, p_topic, p_message):
        """Dispatch a received MQTT message according to the topic.

        TODO: This needs protection from poorly formed Mqtt messages.
        """
        l_topic = p_topic.split('/')[2:]  #  Drop the pyhouse/housename/ as that is all we subscribed to.
        l_message = json_tools.decode_json_unicode(p_message)
        l_logmsg = Actions(self.m_pyhouse_obj).dispatch(l_topic, l_message)
        #  ##
        LOG.info(l_logmsg)
Esempio n. 4
0
 def jsonPair(self, p_json, p_key):
     """ Extract key, value from json
     """
     l_json = json_tools.decode_json_unicode(p_json)
     try:
         l_val = l_json[p_key]
     except (KeyError, ValueError) as e_err:
         l_val = 'ERRor on JsonPair for key "{}"  {} {}'.format(p_key, e_err, l_json)
         print(l_val)
     return l_val
Esempio n. 5
0
 def test_01_Add(self):
     l_node = nodesXml._read_one_node_xml(self.m_xml.node)
     print(PrettyFormatAny.form(l_node, 'Node'))
     l_json = json_tools.encode_json(l_node)
     print(PrettyFormatAny.form(l_json, 'PyHouse'))
     l_msg = json_tools.decode_json_unicode(l_json)
     Util.add_node(self.m_pyhouse_obj, l_msg)
     print(
         PrettyFormatAny.form(self.m_pyhouse_obj.Computer.Nodes, 'PyHouse'))
     self.assertNotEqual(self.m_pyhouse_obj.Xml, TESTING_NODES_NODE_NAME_0)
Esempio n. 6
0
 def jsonPair(self, p_json, p_key):
     """ Extract key, value from json
     """
     l_json = json_tools.decode_json_unicode(p_json)
     try:
         l_val = l_json[p_key]
     except KeyError as e_err:
         print('ERROR - {}'.format(e_err))
         l_val = 'ERRor {}'.format(e_err)
     return l_val
Esempio n. 7
0
 def test_1_CreateJson(self):
     """ Create a JSON object for Rooms.
     """
     self.m_pyhouse_obj.House.Rooms = l_rooms = self.m_api.read_rooms_xml(
         self.m_pyhouse_obj)
     l_json = json_tools.encode_json(l_rooms)
     l_obj = json_tools.decode_json_unicode(l_json)
     # print(PrettyFormatAny.form(l_json, 'JSON', 80))
     # print(PrettyFormatAny.form(l_obj, 'JSON', 80))
     self.assertEqual(len(l_obj), len(l_rooms))
Esempio n. 8
0
 def jsonPair(self, p_json, p_key):
     """ Extract key, value from json
     """
     l_json = json_tools.decode_json_unicode(p_json)
     try:
         l_val = l_json[p_key]
     except KeyError as e_err:
         print('ERROR - {}'.format(e_err))
         l_val = 'ERRor {}'.format(e_err)
     return l_val
Esempio n. 9
0
    def MqttDispatch(self, p_topic, p_message):
        """Dispatch a received MQTT message according to the topic.

        TODO: This needs protection from poorly formed Mqtt messages.
        """
        l_topic = p_topic.split('/')[
            2:]  # Drop the pyhouse/housename/ as that is all we subscribed to.
        l_message = json_tools.decode_json_unicode(p_message)
        l_logmsg = Actions(self.m_pyhouse_obj).mqtt_dispatch(
            l_topic, l_message)
        LOG.info(l_logmsg)
Esempio n. 10
0
 def jsonPair(self, p_json, p_key):
     """ Extract key, value from json
     """
     l_json = json_tools.decode_json_unicode(p_json)
     try:
         l_val = l_json[p_key]
     except (KeyError, ValueError) as e_err:
         l_val = 'ERRor on JsonPair for key "{}"  {} {}'.format(
             p_key, e_err, l_json)
         print(l_val)
     return l_val
Esempio n. 11
0
 def saveControllerData(self, p_json):
     """A new/changed controller is returned.  Process it and update the internal data via controller.py
     """
     l_json = json_tools.decode_json_unicode(p_json)
     l_controller_ix = int(l_json['Key'])
     l_delete = l_json['Delete']
     if l_delete:
         try:
             del self.m_pyhouse_obj.House.Lighting.Controllers[l_controller_ix]
         except AttributeError:
             print("web_controllers - Failed to delete - JSON: {0:}".FORMAT(l_json))
         return
     try:
         l_obj = self.m_pyhouse_obj.House.Lighting.Controllers[l_controller_ix]
     except KeyError:
         l_obj = ControllerData()
     l_obj.Name = l_json['Name']
     l_obj.Active = l_json['Active']
     l_obj.Key = l_controller_ix
     l_obj.Comment = l_json['Comment']
     l_obj.RoomCoords = l_json['RoomCoords']
     l_obj.IsDimmable = l_json['IsDimmable']
     l_obj.DeviceFamily = l_json['DeviceFamily']
     l_obj.RoomName = l_json['RoomName']
     l_obj.LightingType = l_json['LightingType']
     l_obj.UUID = l_json['UUID']
     l_obj.InterfaceType = l_json['InterfaceType']
     l_obj.Port = l_json['Port']
     if l_obj.DeviceFamily == 'Insteon':
         Insteon_utils.Util().get_json_data(l_obj, l_json)
     elif l_obj.DeviceFamily == 'UPB':
         l_obj.UPBAddress = l_json['UPBAddress']
         l_obj.UPBPassword = l_json['UPBPassword']
         l_obj.UPBNetworkID = l_json['UPBNetworkID']
     if l_obj.InterfaceType == 'Serial':
         l_obj.BaudRate = l_json['BaudRate']
     self.m_pyhouse_obj.House.Lighting.Controllers[l_controller_ix] = l_obj
     LOG.info('Controller Added - {}'.format(l_obj))
Esempio n. 12
0
 def saveControllerData(self, p_json):
     """A new/changed controller is returned.  Process it and update the internal data via controller.py
     """
     l_json = json_tools.decode_json_unicode(p_json)
     l_controller_ix = int(l_json['Key'])
     l_delete = l_json['Delete']
     if l_delete:
         try:
             del self.m_pyhouse_obj.House.Lighting.Controllers[l_controller_ix]
         except AttributeError:
             LOG.error("web_controllers - Failed to delete - JSON: {}".FORMAT(l_json))
         return
     try:
         l_obj = self.m_pyhouse_obj.House.Lighting.Controllers[l_controller_ix]
     except KeyError:
         l_obj = ControllerData()
     l_obj.Name = l_json['Name']
     l_obj.Active = l_json['Active']
     l_obj.Key = l_controller_ix
     l_obj.Comment = l_json['Comment']
     l_obj.RoomCoords = l_json['RoomCoords']
     l_obj.IsDimmable = l_json['IsDimmable']
     l_obj.DeviceFamily = l_json['DeviceFamily']
     l_obj.RoomName = l_json['RoomName']
     l_obj.LightingType = l_json['LightingType']
     l_obj.UUID = l_json['UUID']
     l_obj.InterfaceType = l_json['InterfaceType']
     l_obj.Port = l_json['Port']
     if l_obj.DeviceFamily == 'Insteon':
         Insteon_utils.Util().get_json_data(l_obj, l_json)
     elif l_obj.DeviceFamily == 'UPB':
         l_obj.UPBAddress = l_json['UPBAddress']
         l_obj.UPBPassword = l_json['UPBPassword']
         l_obj.UPBNetworkID = l_json['UPBNetworkID']
     if l_obj.InterfaceType == 'Serial':
         l_obj.BaudRate = l_json['BaudRate']
     self.m_pyhouse_obj.House.Lighting.Controllers[l_controller_ix] = l_obj
     LOG.info('Controller Added - {}'.format(l_obj))
Esempio n. 13
0
 def saveUpdateData(self, p_json):
     """A new/changed web is returned.  Process it and update the internal data via ???.py
     """
     l_json = json_tools.decode_json_unicode(p_json)
Esempio n. 14
0
 def saveUpdateData(self, p_json):
     """A new/changed web is returned.  Process it and update the internal data via ???.py
     """
     l_json = json_tools.decode_json_unicode(p_json)
Esempio n. 15
0
 def test_02_Decode(self):
     l_json = json_tools.encode_json(self.m_pyhouse_obj.Computer)
     l_dict = json_tools.decode_json_unicode(l_json)
     # print(debug_tools.PrettyFormatAny.form(l_dict, 'Decoded Inof'))
     self.assertEqual(l_dict['Name'], self.m_pyhouse_obj.Computer.Name)
Esempio n. 16
0
 def test_02_ValidList(self):
     l_json = web_login.LoginElement(self.m_worksapce).getValidLists()
     l_test = json_tools.decode_json_unicode(l_json)
     print(PrettyFormatAny.form(l_test, 'JSON', 40))
     self.assertEqual(l_test['ServerName'], TESTING_NODES_NODE_NAME_0)