def test_03_Broker(self): """ Extract one broker """ l_node = config_tools.Yaml( self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) l_yaml = l_node.Yaml['Mqtt'] l_first_broker = config_tools.Yaml( self.m_pyhouse_obj).find_first_element(l_yaml) l_broker = self.m_config._extract_one_broker(l_first_broker, self) # print('C1-03-A - Yaml: {}'.format(l_first_broker)) # print(PrettyFormatAny.form(l_broker, 'C1-03-B - Broker')) self.assertEqual(l_broker.Name, 'Test Broker 1')
def test_02_ReadFile(self): """ Read the rooms.yaml config file """ l_node = config_tools.Yaml( self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) l_yaml = l_node.Yaml l_first = config_tools.Yaml( self.m_pyhouse_obj).find_first_element(l_yaml) l_yaml_top = l_yaml['Mqtt'] # print(PrettyFormatAny.form(l_node, 'C1-02-A - Node')) # print(PrettyFormatAny.form(l_yaml, 'C1-02-B - Yaml')) # print(PrettyFormatAny.form(l_yaml_top, 'C1-02-C - Yaml_top')) # print(PrettyFormatAny.form(l_yaml_top[0], 'C1-02-D - Yaml_top[0]')) self.assertEqual(l_first, 'Mqtt') self.assertEqual(l_yaml_top[0]['Broker']['Name'], 'Test Broker 1') self.assertEqual(len(l_yaml_top), 2)
def save_yaml_config(self): """ """ LOG.info('Saving Config - Version:{}'.format(__version__)) l_config = self._copy_to_yaml(self.m_pyhouse_obj) config_tools.Yaml(self.m_pyhouse_obj).write_yaml(l_config, CONFIG_FILE_NAME, addnew=True) return l_config
def _copy_to_yaml(self, p_pyhouse_obj): """ Create or Update the yaml information. The information in the YamlTree is updated to be the same as the running pyhouse_obj info. The running info is a dict and the yaml is a list! @return: the updated yaml ready information. """ try: l_node = p_pyhouse_obj._Config.YamlTree[CONFIG_FILE_NAME] l_config = l_node.Yaml['Lighting'] except: l_node = config_tools.Yaml(p_pyhouse_obj).create_yaml_node( 'Lighting') l_config = l_node.Yaml['Lighting'] LOG.debug(PrettyFormatAny.form(p_pyhouse_obj.House, 'PyHouseObj', 190)) l_working = p_pyhouse_obj.House.Lighting.Lights for l_key in [ l_attr for l_attr in dir(l_working) if not l_attr.startswith('_') and not callable(getattr(l_working, l_attr)) ]: l_val = getattr(l_working, l_key) setattr(l_config, l_key, l_val) p_pyhouse_obj._Config.YamlTree[CONFIG_FILE_NAME].Yaml[ 'Lighting'] = l_config l_ret = {'Lighting': l_config} return l_ret
def test_03_ExtractSched(self): """ Extract one room info from the yaml """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) l_yaml = l_node.Yaml l_sched = self.m_config._extract_light_schedule(l_yaml['Schedules'][0]['Light']) print(PrettyFormatAny.form(l_sched, 'F1-03-A - Sched', 190))
def test_04_AllRooms(self): """ build the entire rooms structures """ _l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(self.m_filename) _l_loc = self.m_yaml._update_rooms_from_yaml(self.m_pyhouse_obj, _l_node.Yaml) # print(PrettyFormatAny.form(_l_loc, 'C1-04-A - Loc')) # print(PrettyFormatAny.form(self.m_pyhouse_obj.House.Rooms, 'C1-04-B - Rooms')) self.assertEqual(len(self.m_pyhouse_obj.House.Rooms), 5)
def test_03_Add(self): """ Add a new o the config K,V """ print(PrettyFormatAny.form(self.m_rooms, 'C2-03-A - Rooms', 190)) print(PrettyFormatAny.form(self.m_rooms[4], 'C2-03-B - Room4', 190)) setattr(self.m_rooms[4], 'NewKey', 'A new value') print(PrettyFormatAny.form(self.m_rooms[4], 'C2-03-C - Room4', 190)) l_data = config_tools.Yaml(self.m_pyhouse_obj).dump_string(self.m_rooms) print(l_data) pass
def test_04_AllFloors(self): """ build the entire rooms structures """ _l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml( self.m_filename) _l_loc = self.m_yaml._extract_all_floors(self.m_pyhouse_obj, _l_node.Yaml) # print(PrettyFormatAny.form(_l_loc, 'C1-04-A - Loc')) # print(PrettyFormatAny.form(self.m_pyhouse_obj.House.Floors, 'C1-04-B - Floors')) self.assertEqual(len(self.m_pyhouse_obj.House.Floors), 4)
def test_01_Node(self): """ """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml( self.m_filename) # print(PrettyFormatAny.form(l_node, 'C1-01-A - Node')) self.assertEqual(l_node.FileName, 'location.yaml') self.assertEqual( l_node.YamlPath, '/home/briank/workspace/PyHouse/Project/src/Modules/Housing/_test/Yaml/location.yaml' )
def test_02_ReadFile(self): """ Read the location.yaml config file """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml( self.m_filename) l_config = l_node.Yaml # print(PrettyFormatAny.form(l_node, 'C1-02-A')) # print(PrettyFormatAny.form(l_config, 'C1-02-B')) self.assertEqual(l_config['Location']['Street'], '1600 Pennsylvania Ave NW') self.assertEqual(len(l_config['Location']), 10)
def test_02_ReadFile(self): """ Read the rooms.yaml config file """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) l_yaml = l_node.Yaml l_yamlsched = l_yaml['Schedules'] # print(PrettyFormatAny.form(l_node, 'F1-02-A - Node')) # print(PrettyFormatAny.form(l_yaml, 'F1-02-B - Yaml')) print(PrettyFormatAny.form(l_yamlsched, 'F1-02-C - YamlRooms')) self.assertEqual(l_yamlsched[0]['Name'], 'Base') self.assertEqual(len(l_yamlsched), 3)
def test_02_ReadFile(self): """ Read the rooms.yaml config file """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(self.m_filename) l_yaml = l_node.Yaml l_yamlrooms = l_yaml['Rooms'] print(PrettyFormatAny.form(l_node, 'C1-02-A - Node')) print(PrettyFormatAny.form(l_yaml, 'C1-02-B - Yaml')) print(PrettyFormatAny.form(l_yamlrooms, 'C1-02-C - YamlRooms')) self.assertEqual(l_yamlrooms[0]['Name'], 'Outside') self.assertEqual(len(l_yamlrooms), 5)
def test_02_ReadFile(self): """ Read the rooms.yaml config file """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml( self.m_filename) l_yaml = l_node.Yaml l_yamlcontrollers = l_yaml['Controllers'] # print(PrettyFormatAny.form(l_node, 'C1-02-A - Node')) # print('C1-02-B - Yaml {}'.format(l_yaml['Controllers'])) # print(PrettyFormatAny.form(l_yamlcontrollers, 'C1-02-C - YamlRooms')) self.assertEqual(l_yamlcontrollers[0]['Name'], 'Plm-1') self.assertEqual(len(l_yamlcontrollers), 3)
def test_03_extract(self): """ Create a JSON object for Location. """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml( self.m_filename) l_obj = self.m_config._extract_location(l_node.Yaml['Location']) l_ret = self.m_pyhouse_obj.House.Location # print(PrettyFormatAny.form(l_node, 'C1-03-A')) # print(PrettyFormatAny.form(l_obj, 'C1-03-B')) # print(PrettyFormatAny.form(l_ret, 'C1-03-C')) self.assertEqual(l_obj.Street, '1600 Pennsylvania Ave NW') self.assertEqual(l_obj.City, 'Washington')
def test_03_ExtractFloor(self): """ Extract one room info from the yaml """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml( self.m_filename) l_yamlfloors = l_node.Yaml['Floors'][2] l_obj = self.m_yaml._extract_one_floor(l_yamlfloors) # print(PrettyFormatAny.form(l_yamlfloors, 'C1-03-A')) # print(PrettyFormatAny.form(l_obj, 'C1-03-B')) self.assertEqual(l_obj.Name, '1st') self.assertEqual(l_obj.Comment, 'The first floor') self.assertEqual(l_obj.Floor, 1)
def test_02_ReadFile(self): """ Read the rooms.yaml config file """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(self.m_filename) l_yaml = l_node.Yaml l_config = l_yaml['Bridges'] # print(PrettyFormatAny.form(l_node, 'C1-02-A - Node')) # print(PrettyFormatAny.form(l_yaml, 'C1-02-B - Yaml')) print(PrettyFormatAny.form(l_config, 'C1-02-C - YamlBridges')) print('C1-02-D - Config: {}'.format(l_config)) print('C1-02-E - Config: {}'.format(l_config.item())) self.assertEqual(l_config['Insteon']['Name'], 'Insteon') self.assertEqual(len(l_config), 3)
def load_yaml_config(self): """ Read the .Yaml file. """ # LOG.info('Loading _Config - Version:{}'.format(__version__)) try: l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) except: return None try: l_yaml = l_node.Yaml['Bridges'] except: LOG.warn('The bridges.yaml file does not start with "Bridges"') return None l_bridges = self._extract_all_bridges(l_yaml) self.m_pyhouse_obj.Computer.Bridges = l_bridges return l_node # for testing purposes
def load_yaml_config(self, p_api): """ Read the Mqtt.Yaml file. """ # LOG.info('Reading mqtt config file "{}".'.format(CONFIG_FILE_NAME)) l_node = config_tools.Yaml( self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) if l_node == None: LOG.error('Mossing {}'.format(CONFIG_FILE_NAME)) return None l_yaml = l_node.Yaml l_obj = MqttInformation() l_obj.Brokers = self._extract_all_brokers(l_yaml, p_api) l_obj.ClientID = 'PyH-Comp-' + platform.node() l_obj.Prefix = 'pyhouse/' + self.m_pyhouse_obj._Parameters.Name + '/' # we have not configured house at this point self.m_pyhouse_obj.Core.Mqtt = l_obj return l_obj # for testing purposes
def _extract_devices(self, p_pyhouse_obj, p_yaml): """ Get all devices loaded. """ # LOG.debug('Devices:\n\t{}'.format(p_yaml)) for l_device in p_yaml: # LOG.debug('Key:\n\t{}'.format(l_device)) l_obj = EntertainmentPluginInformation() l_name = config_tools.Yaml(p_pyhouse_obj).find_first_element( l_device) l_ix = l_name.lower() l_obj.Name = l_name l_obj.Type = 'Device' p_pyhouse_obj.House.Entertainment.Plugins[l_ix] = l_obj p_pyhouse_obj.House.Entertainment.PluginCount += 1 # LOG.debug('Devices: {}'.format(PrettyFormatAny.form(p_pyhouse_obj.House.Entertainment))) return l_obj
def save_yaml_config(self): """ Save all the lights in a separate yaml file. """ LOG.info('Saving Config - Version:{}'.format(__version__)) try: l_node = self.m_pyhouse_obj._Config.YamlTree[CONFIG_FILE_NAME] l_config = l_node.Yaml['Lights'] except Exception as e_err: LOG.info( 'No Lights yaml file - creating a new file - {}'.format(e_err)) l_node = config_tools.Yaml( self.m_pyhouse_obj).create_yaml_node('Lights') self.m_pyhouse_obj._Config.YamlTree[CONFIG_FILE_NAME] = l_node l_config = l_node.Yaml['Lights'] # l_config = self._save_all_lights(l_config) # config_tools.Yaml(self.m_pyhouse_obj).write_yaml(l_config, CONFIG_FILE_NAME, addnew=True) return l_config
def load_yaml_config(self): """ Read the pandora.yaml file. """ try: l_node = config_tools.Yaml( self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) except: return None try: l_yaml = l_node.Yaml['Pandora'] except: LOG.warn('The pandora.yaml file does not start with "Pandora:"') return None l_pandora = self._extract_all_pandora(l_yaml) self.m_pyhouse_obj.House.Entertainment.Plugins['pandora'] = l_pandora # self.dump_struct() return l_pandora # for testing purposes
def load_yaml_config(self, p_pyhouse_obj): """ Read the computer.yaml file. """ try: l_node = config_tools.Yaml(p_pyhouse_obj).read_yaml( CONFIG_FILE_NAME) except: LOG.error('The main config file (pyhouse.yaml) is missing!') return None try: l_yaml = l_node.Yaml['PyHouse'] except: LOG.warn('The pyhouse.yaml file does not start with "PyHouse:"') return None l_parameter = self._extract_pyhouse_info(l_yaml) p_pyhouse_obj._Parameters = l_parameter return l_node # for testing purposes
def load_yaml_config(self): """ Read the computer.yaml file. """ try: l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) except: return None try: l_yaml = l_node.Yaml['Computer'] except: LOG.warn('The computer.yaml file does not start with "Computer:"') return None _l_computer = self._extract_computer_info(l_yaml) # self.m_pyhouse_obj.House.Name = l_house.Name # l_obj = self.m_pyhouse_obj.Computer # LOG.debug('Computer.Yaml - {}'.format(l_yaml.Yaml)) return l_node # for testing purposes
def test_02_ReadFile(self): """ Read the rooms.yaml config file """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml( self.m_filename) l_yaml = l_node.Yaml l_yamlfloors = l_yaml['Floors'] # print(PrettyFormatAny.form(l_node, 'C1-02-A - Node')) # print(PrettyFormatAny.form(l_yaml, 'C1-02-B - Yaml')) # print(PrettyFormatAny.form(l_yamlfloors, 'C1-02-C - YamlFloors')) # print(PrettyFormatAny.form(l_yamlfloors[0], 'C1-02-J - Floor-0')) # print(PrettyFormatAny.form(l_yamlfloors[3], 'C1-02-M - Floor-3')) self.assertEqual(l_yamlfloors[0]['Name'], 'Outside') self.assertEqual(l_yamlfloors[1]['Name'], 'Basement') self.assertEqual(l_yamlfloors[2]['Name'], '1st') self.assertEqual(l_yamlfloors[3]['Name'], '2nd') self.assertEqual(len(l_yamlfloors), 4)
def test_03_ExtractRoom(self): """ Extract one room info from the yaml """ l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(self.m_filename) l_yamlrooms = l_node.Yaml['Rooms'][0] l_obj = self.m_yaml._extract_room_config(l_yamlrooms) # print(PrettyFormatAny.form(l_yamlrooms, 'C1-03-A')) # print(PrettyFormatAny.form(l_obj, 'C1-03-B')) self.assertEqual(l_obj.Name, 'Outside') self.assertEqual(l_obj.Active, 'True') self.assertEqual(l_obj.Comment, 'The initial comment') self.assertEqual(l_obj.LastUpdate, datetime(2010, 1, 1, 1, 2, 3)) self.assertEqual(l_obj.Corner, [0.0, 0.0, 0.0]) self.assertEqual(l_obj.Floor, 0) self.assertEqual(l_obj.RoomType, 'OutsideType') self.assertEqual(l_obj.Size, [0.0, 0.0, 0.0]) self.assertEqual(l_obj.Trigger, 'None') self.assertEqual(l_obj.UUID, 'room....-0001-11e6-953b-74da3859e09a')
def load_yaml_config(self): """ Read the outlets.yaml file if it exists. """ try: l_node = config_tools.Yaml( self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) except: self.m_pyhouse_obj.House.Lighting.Outlets = None return None try: l_yaml = l_node.Yaml['Outlets'] except: LOG.warn('The outlets.yaml file does not start with "Outlets:"') self.m_pyhouse_obj.House.Lighting.Outlets = None return None l_outlets = self._extract_all_outlets(l_yaml) self.m_pyhouse_obj.House.Lighting.Outlets = l_outlets return l_outlets # for testing purposes
def load_yaml_config(self): """ Read the pioneer.yaml file. """ # LOG.info('Loading _Config - Version:{}'.format(__version__)) try: l_node = config_tools.Yaml( self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) except: return None try: l_yaml = l_node.Yaml['Pioneer'] except: LOG.warn('The pioneer.yaml file does not start with "Pioneer:"') return None l_pioneer = self._extract_all_pioneer(l_yaml) self.m_pyhouse_obj.House.Entertainment.Plugins['pioneer'] = l_pioneer # self.dump_struct() return l_pioneer # for testing purposes
def load_yaml_config(self): """ Read the Rooms.Yaml file. It contains Rooms data for all rooms in the house. """ # LOG.deb('Loading Config - Version:{}'.format(__version__)) try: l_node = config_tools.Yaml( self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) except: return None try: l_yaml = l_node.Yaml['House'] except: LOG.warn('The house.yaml file does not start with "House:"') return None l_house = self._extract_house_info(l_yaml) self.m_pyhouse_obj.House.Name = l_house.Name return l_node # for testing purposes
def load_yaml_config(self): """ Read the buttons.yaml file if it exists. No file = no buttons. """ # LOG.info('Loading _Config - Version:{}'.format(__version__)) try: l_node = config_tools.Yaml( self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) except: self.m_pyhouse_obj.House.Lighting.Buttons = None return None try: l_yaml = l_node.Yaml['Buttons'] except: LOG.warn('The buttons.yaml file does not start with "Buttons:"') self.m_pyhouse_obj.House.Lighting.Buttons = None return None l_buttons = self._extract_all_button_sets(l_yaml) self.m_pyhouse_obj.House.Lighting.Buttons = l_buttons return l_buttons # for testing purposes
def load_yaml_config(self): """ Read the Rooms.Yaml file. It contains Rooms data for all rooms in the house. """ # LOG.info('Loading _Config - Version:{}'.format(__version__)) try: l_node = config_tools.Yaml(self.m_pyhouse_obj).read_yaml(CONFIG_FILE_NAME) except: self.m_pyhouse_obj.House.Rooms = None return None try: l_yaml = l_node.Yaml['Rooms'] except: LOG.warn('The rooms.yaml file does not start with "Rooms:"') self.m_pyhouse_obj.House.Rooms = None return None l_rooms = self._extract_all_rooms(l_yaml) self.m_pyhouse_obj.House.Rooms = l_rooms return l_rooms # for testing purposes