示例#1
0
    def getValidLists(self):
        """ A JS request for various validating information has been received from the client.

        Return via JSON:
            VALID_DEVICE_TYPES
            VALID_FAMILIES
            VALID_FLOORS
            VALID_INTERFACES
            VALID_LIGHTING_TYPES
            VALID_PROTOCOLS
            VALID_SCHEDULING_TYPES
            VALID_SCHEDULE_MODES
            VALID_TEMP_SYSTEMS
            VALID_THERMOSTAT_MODES
        """
        l_obj = dict(Devices=VALID_DEVICE_TYPES,
                     Families=VALID_FAMILIES,
                     Floors=VALID_FLOORS,
                     InterfaceType=VALID_INTERFACES,
                     LightType=VALID_LIGHTING_TYPE,
                     ProtocolType=VALID_PROTOCOLS,
                     ScheduleType=VALID_SCHEDULING_TYPES,
                     ScheduleMode=VALID_SCHEDULE_MODES,
                     TempSystem=VALID_TEMP_SYSTEMS,
                     ThermostatModes=VALID_THERMOSTAT_MODES,
                     UserRoles=VALID_USER_ROLES)
        l_json = json_tools.encode_json(l_obj)
        return unicode(l_json)
示例#2
0
 def test_06_CreateJson(self):
     """ Create a JSON object for Buttons.
     """
     l_buttons = self.m_api.read_all_buttons_xml(self.m_pyhouse_obj, self.m_xml.button_sect, self.m_version)
     # print('ButtonsS: {0:}'.format(l_buttons))
     # print('Button 0: {0:}'.format(vars(l_buttons[0])))
     l_json = json_tools.encode_json(l_buttons)
示例#3
0
    def getValidLists(self):
        """ A JS request for various validating information has been received from the client.

        Return via JSON:
            VALID_DEVICE_TYPES
            VALID_FAMILIES
            VALID_FLOORS
            VALID_INTERFACES
            VALID_LIGHTING_TYPES
            VALID_PROTOCOLS
            VALID_SCHEDULING_TYPES
            VALID_SCHEDULE_MODES
            VALID_TEMP_SYSTEMS
            VALID_THERMOSTAT_MODES
        """
        l_obj = dict(
                     Devices = VALID_DEVICE_TYPES,
                     Families = VALID_FAMILIES,
                     Floors = VALID_FLOORS,
                     InterfaceType = VALID_INTERFACES,
                     LightType = VALID_LIGHTING_TYPE,
                     ProtocolType = VALID_PROTOCOLS,
                     ScheduleType = VALID_SCHEDULING_TYPES,
                     ScheduleMode = VALID_SCHEDULE_MODES,
                     TempSystem = VALID_TEMP_SYSTEMS,
                     ThermostatModes = VALID_THERMOSTAT_MODES,
                     UserRoles = VALID_USER_ROLES
                     )
        l_json = json_tools.encode_json(l_obj)
        return unicode(l_json)
示例#4
0
 def test_06_CreateJson(self):
     """ Create a JSON object for Buttons.
     """
     l_buttons = self.m_api.read_all_buttons_xml(self.m_pyhouse_obj, self.m_xml.button_sect, self.m_version)
     # print('ButtonsS: {0:}'.format(l_buttons))
     # print('Button 0: {0:}'.format(vars(l_buttons[0])))
     l_json = json_tools.encode_json(l_buttons)
示例#5
0
 def test_01_CreateJson(self):
     """ Create a JSON object for Location.5
     """
     l_house = houseXml.read_house_xml(self.m_pyhouse_obj)
     print('House: {0:}'.format(l_house))
     l_json = json_tools.encode_json(l_house)
     print('JSON: {0:}'.format(l_json))
示例#6
0
 def test_02_Obj(self):
     """ Be sure that the XML contains the right stuff.
     """
     l_obj = LocationData()
     l_obj.Street = '123 Test Street'
     l_obj.City = 'Beverly Hills'
     l_obj.State = 'Confusion'
     l_json = json_tools.encode_json(l_obj)
示例#7
0
 def test_01_CreateJson(self):
     """ Create a JSON object for Location.
     """
     l_obj = lightsAPI.read_all_lights_xml(self.m_pyhouse_obj,
                                           self.m_xml.light_sect)
     print(PrettyFormatAny.form(l_obj, 'Lights'))
     l_json = json_tools.encode_json(l_obj)
     print(PrettyFormatAny.form(l_json, 'JSON'))
示例#8
0
 def test_02_Obj(self):
     """ Be sure that the XML contains the right stuff.
     """
     l_obj = LocationData()
     l_obj.Street = '123 Test Street'
     l_obj.City = 'Beverly Hills'
     l_obj.State = 'Confusion'
     l_json = json_tools.encode_json(l_obj)
示例#9
0
 def test_01_Create(self):
     """ Create a JSON object for Internets.
     """
     l_internet = internetAPI().read_internet_xml(self.m_pyhouse_obj)
     l_json = json_tools.encode_json(l_internet)
     # print(PrettyFormatAny.form(l_json, 'JSON', 70))
     self.assertEqual(self.jsonPair(l_json, 'ExternalIPv4'), convert.str_to_long(TESTING_INTERNET_IPv4))
     self.assertEqual(self.jsonPair(l_json, 'ExternalIPv6'), convert.str_to_long(TESTING_INTERNET_IPv6))
示例#10
0
def GetJSONComputerInfo(p_pyhouse_obj):
    """Get house info for the browser.
    This is simplified and customized so JSON encoding works.

    @param p_house_obj: is the complete information
    """
    l_ret = p_pyhouse_obj.Computer
    l_json = unicode(json_tools.encode_json(l_ret))
    return l_json
示例#11
0
def GetJSONHouseInfo(p_pyhouse_obj):
    """
    Get house info for the browser.

    This is simplified and customized so JSON encoding works.
    """
    l_ret = UtilJson._get_AllHouseObjs(p_pyhouse_obj)
    l_json = unicode(json_tools.encode_json(l_ret))
    return l_json
示例#12
0
 def send_message(self, p_pyhouse_obj, p_topic, p_room_obj):
     """ Messages are:
             room/add - to add a new room to the database.
             room/delete - to delete a room from all nodes
             room/sync - to keep all nodes in sync periodically.
             room/update - to add or modify a room
     """
     l_json = encode_json(p_room_obj)
     p_pyhouse_obj.APIs.Computer.MqttAPI.MqttPublish(p_topic, l_json)
示例#13
0
def GetJSONComputerInfo(p_pyhouse_obj):
    """Get house info for the browser.
    This is simplified and customized so JSON encoding works.

    @param p_house_obj: is the complete information
    """
    l_ret = p_pyhouse_obj.Computer
    l_json = unicode(json_tools.encode_json(l_ret))
    return l_json
示例#14
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)
示例#15
0
 def getInterfaceData(self):
     """ A JS request for information has been received from the client.
     """
     l_interfaces = VALID_INTERFACES
     l_obj = {}
     for l_interface in l_interfaces:
         l_name = l_interface + 'Data'
     l_json = json_tools.encode_json(l_obj)
     return unicode(l_json)
示例#16
0
def GetJSONHouseInfo(p_pyhouse_obj):
    """
    Get house info for the browser.

    This is simplified and customized so JSON encoding works.
    """
    l_ret = UtilJson._get_AllHouseObjs(p_pyhouse_obj)
    l_json = unicode(json_tools.encode_json(l_ret))
    return l_json
示例#17
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)
示例#18
0
 def getInterfaceData(self):
     """ A JS request for information has been received from the client.
     """
     l_interfaces = VALID_INTERFACES
     l_obj = {}
     for l_interface in l_interfaces:
         l_name = l_interface + 'Data'
     l_json = json_tools.encode_json(l_obj)
     return unicode(l_json)
示例#19
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))
示例#20
0
 def test_01_Create(self):
     """ Create a JSON object for Internets.
     """
     l_internet = internetAPI().read_internet_xml(self.m_pyhouse_obj)
     l_json = json_tools.encode_json(l_internet)
     # print(PrettyFormatAny.form(l_json, 'JSON', 70))
     self.assertEqual(self.jsonPair(l_json, 'ExternalIPv4'),
                      convert.str_to_long(TESTING_INTERNET_IPv4))
     self.assertEqual(self.jsonPair(l_json, 'ExternalIPv6'),
                      convert.str_to_long(TESTING_INTERNET_IPv6))
示例#21
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)
示例#22
0
 def getUsersData(self):
     """
     Get a lot of server JSON data and pass it to the client browser.
     """
     l_users = self.m_pyhouse_obj.Computer.Web.Logins
     LOG.debug(PrettyFormatAny.form(l_users, 'Login users'))
     if l_users == {}:
         l_users[0] = LoginData()
         l_users[0].Name = 'admin'
         l_users[0].LoginPasswordCurrent = 'admin'
         l_users[0].LoginFullName = 'Administrator'
         l_users[0].LoginRole = 1
         self.m_pyhouse_obj.Computer.Web.Logins = l_users
         LOG.debug('Creating fake user since there was none')
     l_json = unicode(json_tools.encode_json(l_users))
     LOG.info('Fetched {}'.format(l_json))
     return l_json
示例#23
0
 def getUsersData(self):
     """
     Get a lot of server JSON data and pass it to the client browser.
     """
     l_users = self.m_pyhouse_obj.Computer.Web.Logins
     # LOG.debug(PrettyFormatAny.form(l_users, 'Login users'))
     if l_users == {}:
         l_users[0] = LoginData()
         l_users[0].Name = 'admin'
         l_users[0].LoginPasswordCurrent = 'admin'
         l_users[0].LoginFullName = 'Administrator'
         l_users[0].LoginRole = 1
         self.m_pyhouse_obj.Computer.Web.Logins = l_users
         # LOG.debug('Creating fake user since there was none')
     l_json = unicode(json_tools.encode_json(l_users))
     # LOG.info('Fetched {}'.format(l_json))
     return l_json
示例#24
0
 def _make_message(p_pyhouse_obj, p_message = None):
     """
     @param p_pyhouse_obj: is the entire PyHouse Data tree.
     @param message_json: is message that is already json encoded\
     @param message_obj: is additional object that will be added into the meddage as Json.
     """
     l_message = MqttJson()
     l_message.Sender = p_pyhouse_obj.Computer.Name
     l_message.DateTime = datetime.datetime.now()
     if p_message == None:
         pass
     elif isinstance(p_message, object):
         xml_tools.stuff_new_attrs(l_message, p_message)
     else:
         xml_tools.stuff_new_attrs(l_message, p_message)
     #  print(PrettyFormatAny.form(l_message, 'Mqtt Client - Message'))
     l_json = json_tools.encode_json(l_message)
     return l_json
示例#25
0
    def doLogin(self, p_json):
        """ This will receive json of username, password when the user clicks on the login button in the browser.

            First, we validate the user
            If valid, display the user and then the root menu.
            If not - allow the user to retry the login.

            also

            allow user to check the change button and apply the change after logging in the user.

            @param p_json: is the username and password passed back by the client.
        """
        LOG.info("doLogin called {}.".format(PrettyFormatAny.form(p_json, 'Login From Browser')))
        l_obj = web_utils.JsonUnicode().decode_json(p_json)
        l_login_obj = self.validate_user(l_obj)
        l_json = json_tools.encode_json(l_login_obj)
        return unicode(l_json)
示例#26
0
 def _make_message(p_pyhouse_obj, p_message=None):
     """
     @param p_pyhouse_obj: is the entire PyHouse Data tree.
     @param message_json: is message that is already json encoded\
     @param message_obj: is additional object that will be added into the meddage as Json.
     """
     l_message = MqttJson()
     l_message.Sender = p_pyhouse_obj.Computer.Name
     l_message.DateTime = datetime.datetime.now()
     if p_message is None:
         pass
     elif isinstance(p_message, object):
         xml_tools.stuff_new_attrs(l_message, p_message)
     else:
         xml_tools.stuff_new_attrs(l_message, p_message)
     #  print(PrettyFormatAny.form(l_message, 'Mqtt Client - Message'))
     l_json = json_tools.encode_json(l_message)
     return l_json
示例#27
0
    def doLogin(self, p_json):
        """ This will receive json of username, password when the user clicks on the login button in the browser.

            First, we validate the user
            If valid, display the user and then the root menu.
            If not - allow the user to retry the login.

            also

            allow user to check the change button and apply the change after logging in the user.

            @param p_json: is the username and password passed back by the client.
        """
        LOG.info("doLogin called {}.".format(
            PrettyFormatAny.form(p_json, 'Login From Browser')))
        l_obj = web_utils.JsonUnicode().decode_json(p_json)
        l_login_obj = self.validate_user(l_obj)
        l_json = json_tools.encode_json(l_login_obj)
        return unicode(l_json)
示例#28
0
 def test_01_CreateJson(self):
     """ Create a JSON object for Location.
     """
     l_controller = self.m_api.read_all_controllers_xml(self.m_pyhouse_obj, self.m_xml.controller_sect, self.m_version)
     l_json = json_tools.encode_json(l_controller)
     print(l_json)
示例#29
0
 def test_01_Room(self):
     l_rooms = self.m_api.read_one_room(self.m_xml.room)
     l_json = unicode(json_tools.encode_json(l_rooms))
示例#30
0
 def test_07_CreateJson(self):
     """ Create a JSON object for Rooms.
     """
     self.m_pyhouse_obj.House.Rooms = l_rooms = self.m_api.read_rooms_xml(self.m_xml.house_div)
     l_json = json_tools.encode_json(l_rooms)
示例#31
0
 def getServerInfo(self):
     """ A JS request
     """
     l_obj = dict(ServerName=self.m_pyhouse_obj.Computer.Name)
     l_json = json_tools.encode_json(l_obj)
     return unicode(l_json)
示例#32
0
 def getUpdateData(self):
     """ A JS client has requested all the webs information.
     """
     l_obj = self.m_pyhouse_obj.Computer.Web
     l_json = unicode(json_tools.encode_json(l_obj))
     return l_json
 def test_01_CreateJson(self):
     """ Create a JSON object for Location.
     """
     l_controller = self.m_api.read_all_controllers_xml(self.m_pyhouse_obj)
     l_json = json_tools.encode_json(l_controller)
     print(l_json)
示例#34
0
 def test_01_Json_Encode(self):
     x = PY_DATA
     y = json_tools.encode_json(x)
示例#35
0
 def getUpdateData(self):
     """ A JS client has requested all the webs information.
     """
     l_obj = self.m_pyhouse_obj.Computer.Web
     l_json = unicode(json_tools.encode_json(l_obj))
     return l_json
示例#36
0
 def test_01_Room(self):
     l_rooms = self.m_api.read_one_room(self.m_xml.room)
     l_json = unicode(json_tools.encode_json(l_rooms))
示例#37
0
 def test_02_Rooms(self):
     l_rooms = self.m_api.read_rooms_xml(self.m_xml.house_div)
     l_json = unicode(json_tools.encode_json(l_rooms))
示例#38
0
 def test_01_Json_Encode(self):
     x = PY_DATA
     y = json_tools.encode_json(x)
示例#39
0
 def test_01_CreateJson(self):
     """ Create a JSON object for Location.
     """
     l_obj = lightsAPI.read_all_lights_xml(self.m_pyhouse_obj, self.m_xml.light_sect, self.m_version)
     #  print('Light: {0:}'.format(l_obj))
     l_json = json_tools.encode_json(l_obj)
示例#40
0
 def test_02_Rooms(self):
     l_rooms = self.m_api.read_rooms_xml(self.m_xml.house_div)
     l_json = unicode(json_tools.encode_json(l_rooms))
示例#41
0
 def test_01_Encode(self):
     l_json = json_tools.encode_json(self.m_pyhouse_obj)
     print(l_json)
     # PrettyFormatAny.form(l_json, "PyHouse_Obj")
     self.assertSubstring('Xml', l_json)
     self.assertSubstring('XmlOldVersion', l_json)
示例#42
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)