Esempio n. 1
0
def get_room_info(p_obj, p_json_decoded):
        l_coords = CoordinateData()
        l_coords.X_Easting = p_json_decoded['RoomCoords'][0]
        l_coords.Y_Northing = p_json_decoded['RoomCoords'][1]
        l_coords.Z_Height = p_json_decoded['RoomCoords'][2]
        p_obj.RoomCoords = l_coords
        p_obj.RoomName = p_json_decoded['RoomName']
        p_obj.RoomUUID = p_json_decoded['RoomUUID']
        return p_obj
Esempio n. 2
0
 def saveLightData(self, p_json):
     """A new/changed light is returned.  Process it and update the internal data via light_xxxx.py
     """
     l_json = JsonUnicode().decode_json(p_json)
     l_delete = l_json['Delete']
     l_light_ix = int(l_json['Key'])
     if l_delete:
         try:
             del self.m_pyhouse_obj.House.Lighting.Lights[l_light_ix]
         except AttributeError:
             LOG.error("web_lights - Failed to delete - JSON: {0:}".format(
                 l_json))
         return
     try:
         l_obj = self.m_pyhouse_obj.House.Lighting.Lights[l_light_ix]
     except KeyError:
         LOG.warning(
             'Creating a new light for light {0:}'.format(l_light_ix))
         l_obj = lighting_lights.LightData()
     #
     l_obj.Name = l_json['Name']
     l_obj.Active = l_json['Active']
     l_obj.Key = l_light_ix
     l_obj.Comment = l_json['Comment']
     l_coords = CoordinateData()
     l_coords.X_Easting = l_json['RoomCoords'][0]
     l_coords.Y_Northing = l_json['RoomCoords'][1]
     l_coords.Z_Height = l_json['RoomCoords'][2]
     l_obj.RoomCoords = l_coords
     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']
     #  if len(l_obj.UUID) < 8:
     #    l_obj.UUID = str(uuid.uuid1())
     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']
     self.m_pyhouse_obj.House.Lighting.Lights[l_light_ix] = l_obj
Esempio n. 3
0
 def saveLightData(self, p_json):
     """A new/changed light is returned.  Process it and update the internal data via light_xxxx.py
     """
     l_json = JsonUnicode().decode_json(p_json)
     print(PrettyFormatAny.form(l_json, 'JSON'))
     l_delete = l_json['Delete']
     l_light_ix = int(l_json['Key'])
     if l_delete:
         try:
             del self.m_pyhouse_obj.House.Lighting.Lights[l_light_ix]
         except AttributeError:
             LOG.error("web_lights - Failed to delete - JSON: {0:}".format(l_json))
         return
     try:
         l_obj = self.m_pyhouse_obj.House.Lighting.Lights[l_light_ix]
     except KeyError:
         LOG.warning('Creating a new light for light {0:}'.format(l_light_ix))
         l_obj = lighting_lights.LightData()
     #
     l_obj.Name = l_json['Name']
     l_obj.Active = l_json['Active']
     l_obj.Key = l_light_ix
     l_obj.Comment = l_json['Comment']
     l_coords = CoordinateData()
     l_coords.X_Easting = l_json['RoomCoords'][0]
     l_coords.Y_Northing = l_json['RoomCoords'][1]
     l_coords.Z_Height = l_json['RoomCoords'][2]
     l_obj.RoomCoords = l_coords
     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']
     #  if len(l_obj.UUID) < 8:
     #    l_obj.UUID = str(uuid.uuid1())
     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']
     self.m_pyhouse_obj.House.Lighting.Lights[l_light_ix] = l_obj
Esempio n. 4
0
    def get_coords_from_xml(p_xml, p_name):
        def _get_float(p_field):
            l_fld = str.strip(p_field, '\"\' ')
            l_flt = float(l_fld)
            return l_flt

        l_ret = CoordinateData()
        l_raw = XML.get_any_field(p_xml, p_name)
        #  LOG.info('Name:{};  Field:{}'.format(p_name, l_raw))
        try:
            l_raw = str.strip(l_raw, ' \"\'[]')
            l_field = str.split(l_raw, ',')
            l_ret.X_Easting = _get_float(l_field[0])
            l_ret.Y_Northing = _get_float(l_field[1])
            l_ret.Z_Height = _get_float(l_field[2])
        except Exception as e_err:
            l_ret.X_Easting = 0.0
            l_ret.Y_Northing = 0.0
            l_ret.Z_Height = 0.0
            LOG.error('CoOrd Error {}'.format(e_err))
        return l_ret
Esempio n. 5
0
    def _get_coords(p_coords):
        """ get CordinateData() from JSON data returned from the browser

        @param p_str: Json returns a list of X, Y and Z values.
                        It should look like >> [ 1, 2.2, 33.44 ] but it could be deformed by the user.
        @return: a CoordinateData() object filled in.
        """
        l_ret = CoordinateData()
        if isinstance(p_coords, list):
            l_list = p_coords
        else:
            l_list = p_coords.strip('\[\]')
            l_list = l_list.split(',')
        try:
            l_ret.X_Easting = float(l_list[0])
            l_ret.Y_Northing = float(l_list[1])
            l_ret.Z_Height = float(l_list[2])
        except Exception as e_err:
            print('Error {}'.format(e_err))
            l_ret.X_Easting = 0.0
            l_ret.Y_Northing = 0.0
            l_ret.Z_Height = 0.0
        return l_ret
Esempio n. 6
0
 def get_coords_from_xml(p_xml, p_name):
     def _get_float(p_field):
         l_fld = str.strip(p_field, '" ')
         l_fld = str.strip(l_fld, "' ")
         l_flt = float(l_fld)
         return l_flt
     l_ret = CoordinateData()
     l_raw = XML.get_any_field(p_xml, p_name)
     #  LOG.info('Name:{};  Field:{}'.format(p_name, l_raw))
     try:
         l_raw = str.strip(l_raw, ' []')
         l_field = str.split(l_raw, ',')
         l_ret.X_Easting = _get_float(l_field[0])
         l_ret.Y_Northing = _get_float(l_field[1])
         l_ret.Z_Height = _get_float(l_field[2])
     except:
         l_ret.X_Easting = 0.0
         l_ret.Y_Northing = 0.0
         l_ret.Z_Height = 0.0
     return l_ret
Esempio n. 7
0
    def get_coords_from_xml(p_xml, p_name):

        def _get_float(p_field):
            l_fld = str.strip(p_field, '\"\' ')
            l_flt = float(l_fld)
            return l_flt

        l_ret = CoordinateData()
        l_raw = XML.get_any_field(p_xml, p_name)
        #  LOG.info('Name:{};  Field:{}'.format(p_name, l_raw))
        try:
            l_raw = str.strip(l_raw, ' \"\'[]')
            l_field = str.split(l_raw, ',')
            l_ret.X_Easting = _get_float(l_field[0])
            l_ret.Y_Northing = _get_float(l_field[1])
            l_ret.Z_Height = _get_float(l_field[2])
        except Exception as _e_err:
            l_ret.X_Easting = 0.0
            l_ret.Y_Northing = 0.0
            l_ret.Z_Height = 0.0
            # LOG.error('CoOrd Error {}'.format(e_err))
        return l_ret