예제 #1
0
 def test_02_Decode(self):
     # l_json = json_tools.encode_json(self.m_pyhouse_obj.Computer)
     l_json = json_tools.encode_json(MSG_DICT)
     print(PrettyFormatAny.form(l_json, 'A1-02-A - Encoded Info'))
     l_dict = json_tools.decode_json_unicode(l_json)
     print(l_dict)
     print(PrettyFormatAny.form(l_dict, 'A1-02-B - Decoded Info'))
예제 #2
0
 def test_06_CreateJson(self):
     """ Create a JSON object for Buttons.
     """
     # print('ButtonsS: {}'.format(l_doors))
     # print('Button 0: {}'.format(vars(l_doors[0])))
     l_json = json_tools.encode_json(
         self.m_pyhouse_obj.House.Security.GarageDoors)
예제 #3
0
 def test_02_Decode(self):
     # l_json = json_tools.encode_json(self.m_pyhouse_obj.Computer)
     l_json = json_tools.encode_json(MSG_DICT)
     print(PrettyFormatAny.form(l_json, 'A1-02-A - Encoded Info'))
     l_dict = json_tools.decode_json_unicode(l_json)
     print(l_dict)
     print(PrettyFormatAny.form(l_dict, 'A1-02-B - Decoded Info'))
예제 #4
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,
                     InterfaceTypes=VALID_INTERFACES,
                     LightTypes=VALID_LIGHTING_TYPE,
                     ProtocolTypes=VALID_PROTOCOLS,
                     ScheduleTypes=VALID_SCHEDULING_TYPES,
                     ScheduleModes=VALID_SCHEDULE_MODES,
                     TempSystems=VALID_TEMP_SYSTEMS,
                     ThermostatModes=VALID_THERMOSTAT_MODES,
                     UserRoles=VALID_USER_ROLES
                     )
        l_json = json_tools.encode_json(l_obj)
        return l_json
예제 #5
0
 def test_06_CreateJson(self):
     """ Create a JSON object for Buttons.
     """
     l_button = buttonsXML().read_all_buttons_xml(self.m_pyhouse_obj)
     self.m_pyhouse_obj.House.Lighting.Buttons = l_button
     # print('Buttons: {}'.format(l_button))
     # print('Button 0: {}'.format(vars(l_button[0])))
     l_json = json_tools.encode_json(l_button)
예제 #6
0
 def test_06_CreateJson(self):
     """ Create a JSON object for Buttons.
     """
     l_button = self.m_api.read_all_buttons_xml(self.m_pyhouse_obj)
     self.m_pyhouse_obj.House.Lighting.Buttons = l_button
     # print('Buttons: {}'.format(l_button))
     # print('Button 0: {}'.format(vars(l_button[0])))
     l_json = json_tools.encode_json(l_button)
예제 #7
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)
예제 #8
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)
예제 #9
0
 def test_01_CreateJson(self):
     """ Create a JSON object for Location.
     """
     l_obj = lightsAPI.read_all_lights_xml(self.m_pyhouse_obj)
     # print(PrettyFormatAny.form(l_obj, 'Z1-01-A - Lights'))
     l_json = json_tools.encode_json(l_obj)
     # print(PrettyFormatAny.form(l_json, 'Z1-01-B - JSON'))
     self.assertEqual(l_json[0], '{')
예제 #10
0
 def test_02_Obj(self):
     """ Be sure that the XML contains the right stuff.
     """
     l_obj = LocationInformationPrivate()
     l_obj.Street = '123 Test Street'
     l_obj.City = 'Beverly Hills'
     l_obj.State = 'Confusion'
     _l_json = json_tools.encode_json(l_obj)
예제 #11
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)
예제 #12
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)
예제 #13
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)
예제 #14
0
 def test_02_Who(self):
     l_node = nodesXml._read_one_node_xml(self.m_xml.node)
     # print(PrettyFormatAny.form(l_node, 'C1-01-A - Node'))
     l_json = json_tools.encode_json(l_node)
     # print(PrettyFormatAny.form(l_json, 'C1-01-B - 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, 'C1-01-C - PyHouse'))
     self.assertNotEqual(self.m_pyhouse_obj.Xml, TESTING_NODES_NODE_NAME_0)
예제 #15
0
 def test_02_Who(self):
     l_node = nodesXml._read_one_node_xml(self.m_xml.node)
     # print(PrettyFormatAny.form(l_node, 'C1-01-A - Node'))
     l_json = json_tools.encode_json(l_node)
     # print(PrettyFormatAny.form(l_json, 'C1-01-B - 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, 'C1-01-C - PyHouse'))
     self.assertNotEqual(self.m_pyhouse_obj.Xml, TESTING_NODES_NODE_NAME_0)
예제 #16
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
예제 #17
0
 def test_01_CreateJson(self):
     """ Create a JSON object for Rooms.
     """
     self.m_pyhouse_obj.House.Rooms = l_rooms = self.m_api(self.m_pyhouse_obj).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))
예제 #18
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('house/room/' + p_topic, l_json)
예제 #19
0
파일: rooms.py 프로젝트: bopopescu/PyHouse
 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)
     l_topic = 'house/room/' + p_topic
     p_pyhouse_obj._APIs.Core.MqttAPI.MqttPublish(l_topic, l_json)
예제 #20
0
 def test_01_Create(self):
     """ Create a JSON object for Location.5
     """
     l_house = houseXml.read_house_xml(self.m_pyhouse_obj)
     # print(PrettyFormatAny.form(l_house, 'J1-01-A - House'))
     l_json = json_tools.encode_json(l_house)
     # print('J1-01-B - JSON: {}'.format(l_json))
     l_decoded = json_tools.decode_json_unicode(l_json)
     # print(PrettyFormatAny.form(l_decoded, 'J1-01-C - Decoded'))
     self.assertEqual(l_decoded['Name'], TESTING_HOUSE_NAME)
예제 #21
0
def generate_light_body_json(p_light_control):
    """ Convert internal data to hue control data and format

    @param p_light_control: ==> LightData() in Housing.Lighting.lighting_lights
    @returns: json body to control lights
                {
                    "on": true,
                    "bri": 254
                }
    """
    if p_light_control.BrightnessPct == 0:
        l_body = {'on': 'false'}
    else:
        l_bright = int(p_light_control.BrightnessPct * 254 / 100)
        l_body = {'on': 'true', 'bri': '{}'.format(l_bright)}
    return encode_json(l_body)
예제 #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 = json_tools.encode_json(l_users)
     # LOG.info('Fetched {}'.format(l_json))
     return l_json
예제 #23
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)
    l_json = json_tools.encode_json(l_message)
    return l_json
예제 #24
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
예제 #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 = json_tools.decode_json_unicode(p_json)
        l_login_obj = self.validate_user(l_obj)
        l_json = json_tools.encode_json(l_login_obj)
        return l_json
예제 #26
0
def GetJSONHouseInfo(p_pyhouse_obj):
    """
    Get house info for the browser.

    This is simplified and customized so JSON encoding works.
    """
    l_ret = JsonHouseData()
    l_ret.Name = p_pyhouse_obj.House.Name
    l_ret.Key = p_pyhouse_obj.House.Key
    l_ret.Active = p_pyhouse_obj.House.Active
    l_ret.Hvac = p_pyhouse_obj.House.Hvac
    l_ret.Irrigation = p_pyhouse_obj.House.Irrigation
    l_ret.Lighting = UtilJson._get_Lighting(p_pyhouse_obj)
    l_ret.Location = p_pyhouse_obj.House.Location
    l_ret.Rooms = p_pyhouse_obj.House.Rooms
    l_ret.Schedules = p_pyhouse_obj.House.Schedules
    l_ret.Security = p_pyhouse_obj.House.Security
    l_json = unicode(json_tools.encode_json(l_ret))
    return l_json
예제 #27
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)
예제 #28
0
 def test_02_Rooms(self):
     l_rooms = self.m_api.read_rooms_xml(self.m_pyhouse_obj)
     l_json = unicode(json_tools.encode_json(l_rooms))
 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)
예제 #30
0
 def getWebsData(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
예제 #31
0
 def test_01_Encode(self):
     l_json = json_tools.encode_json(MSG_DICT)
     print(PrettyFormatAny.form(l_json, 'A1-01-A - JSON'))
     print(PrettyFormatObject(l_json, 'A1-01-B - JSON'))
     self.assertSubstring('Street', l_json)
     self.assertSubstring('Elevation', 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
예제 #33
0
 def test_06_CreateJson(self):
     """ Create a JSON object for Buttons.
     """
     # print('ButtonsS: {}'.format(l_doors))
     # print('Button 0: {}'.format(vars(l_doors[0])))
     l_json = json_tools.encode_json(self.m_pyhouse_obj.House.Security.GarageDoors)
예제 #34
0
 def test_01_Encode(self):
     l_json = json_tools.encode_json(MSG_DICT)
     print(PrettyFormatAny.form(l_json, 'A1-01-A - JSON'))
     print(PrettyFormatObject(l_json, 'A1-01-B - JSON'))
     self.assertSubstring('Street', l_json)
     self.assertSubstring('Elevation', l_json)
예제 #35
0
 def test_02_Rooms(self):
     l_rooms = self.m_api.read_rooms_xml(self.m_pyhouse_obj)
     l_json = unicode(json_tools.encode_json(l_rooms))