def advance_publish(self): """Read system status and return the results""" values = {} matrix = [] _log.debug("Advancing simulation") self.conn.send(body='advance', destination=request_queue, headers={"content-type": "text/plain"}) self.conn.get_listener(name='').wait_for_message() response = self.conn.get_listener(name='').get_latest_message() rows = response[1].split(';') building_power = rows[building_power_row_index] timestamp_value = rows[timestamp_row] for rows_string in rows[:4]: row = [float(x) for x in rows_string.split()] matrix.append(row) for column_index, device_config in enumerate(status_format): device_name, point_map = device_config device_result = {} for point_name, row_index in point_map.items(): value = matrix[row_index][column_index] device_result[point_name] = value values[device_name] = device_result #building_power = matrix[0][building_power_row_index] now = dateutil.parser.parse(timestamp_value) headers = {headers_mod.DATE: now.isoformat()} _log.debug("Simulation time: " + str(now)) _log.debug("Returned simulation values: " + str(values)) for device_name, device_results in values.items(): publish_topic = DEVICES_VALUE(campus='', building='', unit=device_name, point='all') self._publish_wrapper(publish_topic, headers=headers, message=[device_results, {}]) publish_topic = DEVICES_VALUE(campus='', building='', unit=building_power_device, point='all') self._publish_wrapper(publish_topic, headers=headers, message=[{ building_power_point: building_power }, {}])
def setup_device(self): config = self.config driver_config = config["driver_config"] driver_type = config["driver_type"] registry_config = config.get("registry_config") self.heart_beat_point = config.get("heart_beat_point") _log.info("Registry config of {} is {}".format(driver_type, registry_config)) _log.info("Driver config of {} is {}".format(driver_type, driver_config)) self.interface = self.get_interface(driver_type, driver_config, registry_config) self.meta_data = {} for point in self.interface.get_register_names(): register = self.interface.get_register_by_name(point) self.meta_data[point] = {'units': register.get_units(), 'type': self.register_data_type(register), 'tz': config.get('timezone', '')} self.base_topic = DEVICES_VALUE(campus='', building='', unit='', path=self.device_path, point=None) self.device_name = DEVICES_PATH(base='', node='', campus='', building='', unit='', path=self.device_path, point='')
def setup_device(self): #First call to setup_device won't have anything to unsubscribe to. # try: # self.vip.pubsub.unsubscribe('pubsub', None, None) # except KeyError: # pass #config = self.get_config(self.core.identity) #self.config = jsonapi.loads(utils.strip_comments(config)) driver_config = config["driver_config"] driver_type = config["driver_type"] registry_config = self.get_config(config["registry_config"]) self.heart_beat_point = config.get("heart_beat_point") self.interface = self.get_interface(driver_type, driver_config, registry_config) self.meta_data = {} for point in self.interface.get_register_names(): register = self.interface.get_register_by_name(point) if register.register_type == 'bit': ts_type = 'boolean' else: if register.python_type is int: ts_type = 'integer' elif register.python_type is float: ts_type = 'float' elif register.python_type is str: ts_type = 'string' self.meta_data[point] = { 'units': register.get_units(), 'type': ts_type, 'tz': config['timezone'] } self.base_topic = DEVICES_VALUE(campus=config.get('campus', ''), building=config.get( 'building', ''), unit=config.get('unit', ''), path=config.get('path', ''), point=None) self.device_name = DEVICES_PATH(base='', node='', campus=config.get('campus', ''), building=config.get( 'building', ''), unit=config.get('unit', ''), path=config.get('path', ''), point='') #self.parent.device_startup_callback(self.device_name, self.core.identity) self.vip.rpc.call('platform.driver', 'device_startup_callback', self.device_name)
def setup_device(self): config = self.config driver_config = config["driver_config"] driver_type = config["driver_type"] registry_config = config.get("registry_config") self.heart_beat_point = config.get("heart_beat_point") self.publish_depth_first_all = bool( config.get("publish_depth_first_all", True)) self.publish_breadth_first_all = bool( config.get("publish_breadth_first_all", True)) self.publish_depth_first = bool(config.get("publish_depth_first", True)) self.publish_breadth_first = bool( config.get("publish_breadth_first", True)) self.interface = self.get_interface(driver_type, driver_config, registry_config) self.meta_data = {} for point in self.interface.get_register_names(): register = self.interface.get_register_by_name(point) if register.register_type == 'bit': ts_type = 'boolean' else: if register.python_type is int: ts_type = 'integer' elif register.python_type is float: ts_type = 'float' elif register.python_type is str: ts_type = 'string' self.meta_data[point] = { 'units': register.get_units(), 'type': ts_type, 'tz': config['timezone'] } self.base_topic = DEVICES_VALUE(campus='', building='', unit='', path=self.device_path, point=None) self.device_name = DEVICES_PATH(base='', node='', campus='', building='', unit='', path=self.device_path, point='')