def set_environment_reported_actuator_value( self, variable: str, value: Any ) -> None: """Sets reported actuator value to shared environment state.""" set_nested_dict_safely( self.environment, ["actuator", "reported", variable], value, self.lock )
def set_peripheral_desired_sensor_value(self, peripheral, variable, value): """ Sets desired sensor value to shared peripheral state. """ set_nested_dict_safely( self.peripherals, [peripheral, "sensor", "desired", variable], value, self.lock, )
def set_peripheral_reported_actuator_value(self, peripheral, variable, value): """ Sets reported actuator value to shared peripheral state. """ set_nested_dict_safely( self.peripherals, [peripheral, "actuator", "reported", variable], value, self.lock, )
def set_peripheral_desired_actuator_value( self, peripheral: str, variable: str, value: Any ) -> None: """Sets desired actuator value to shared peripheral state.""" set_nested_dict_safely( self.peripherals, [peripheral, "actuator", "desired", variable], value, self.lock, )
def set_peripheral_reported_sensor_value( self, peripheral: str, variable: str, value: Any ) -> None: """Sets reported sensor value to shared peripheral state.""" set_nested_dict_safely( self.peripherals, [peripheral, "sensor", "reported", variable], value, self.lock, )
def run_config_mode(self) -> None: """Runs configuration mode. If device config is not set, loads 'unspecified' config then transitions to setup mode.""" self.logger.info("Entered CONFIG") # Check device config specifier file exists in repo try: with open(DEVICE_CONFIG_PATH) as f: config_name = f.readline().strip() except: env_dev_type = os.getenv("OPEN_AG_DEVICE_TYPE") if env_dev_type is None: config_name = "unspecified" message = "Unable to read {}, using unspecified config".format( DEVICE_CONFIG_PATH ) else: config_name = env_dev_type message = "Unable to read {}, using {} config from env".format( DEVICE_CONFIG_PATH, config_name ) self.logger.warning(message) # Create the directories if needed os.makedirs(os.path.dirname(DEVICE_CONFIG_PATH), exist_ok=True) # Write `unspecified` to device.txt with open(DEVICE_CONFIG_PATH, "w") as f: f.write("{}\n".format(config_name)) # Load device config self.logger.debug("Loading device config file: {}".format(config_name)) device_config = json.load(open("data/devices/{}.json".format(config_name))) # Check if config uuid changed, if so, adjust state if self.config_uuid != device_config["uuid"]: with self.state.lock: self.state.peripherals = {} self.state.controllers = {} set_nested_dict_safely( self.state.environment, ["reported_sensor_stats"], {}, self.state.lock, ) set_nested_dict_safely( self.state.environment, ["sensor", "reported"], {}, self.state.lock ) self.config_uuid = device_config["uuid"] # Transition to setup mode on next state machine update self.mode = modes.SETUP
def run_config_mode(self): """Runs configuration mode. If device config is not set, loads 'unspecified' config then transitions to setup mode.""" self.logger.info("Entered CONFIG") # Check device config specifier file exists in repo DEVICE_CONFIG_PATH = "data/config/device.txt" try: with open(DEVICE_CONFIG_PATH) as f: config_name = f.readline().strip() except: message = "Unable to read {}, using unspecified config".format( DEVICE_CONFIG_PATH) self.logger.warning(message) config_name = "unspecified" # Write `unspecified` to device.txt with open(DEVICE_CONFIG_PATH, "w") as f: f.write("{}\n".format(config_name)) # Load device config self.logger.debug("Loading device config file: {}".format(config_name)) device_config = json.load( open("data/devices/{}.json".format(config_name))) # Check if config uuid changed, if so, adjust state if self.config_uuid != device_config["uuid"]: with self.state.lock: self.state.peripherals = {} set_nested_dict_safely( self.state.environment, ["reported_sensor_stats"], {}, self.state.lock, ) set_nested_dict_safely(self.state.environment, ["sensor", "reported"], {}, self.state.lock) self.config_uuid = device_config["uuid"] # Check for transitions if self.transitions.is_new(Modes.CONFIG): return # Transition to SETUP self.mode = Modes.SETUP
def set_controller_value(self, controller: str, variable: str, value: Any) -> None: """Sets controller to shared controller state.""" set_nested_dict_safely( self.controllers, [controller, variable], value, self.lock )
def set_peripheral_value(self, peripheral: str, variable: str, value: Any) -> None: """Sets peripheral to shared peripheral state.""" set_nested_dict_safely( self.peripherals, [peripheral, variable], value, self.lock )
def set_environment_desired_sensor_value(self, variable: str, value: Any) -> None: """Sets desired sensor value to shared environment state.""" set_nested_dict_safely( self.environment, ["sensor", "desired", variable], value, self.lock )
def set_environment_desired_actuator_value(self, variable, value): """ Sets desired actuator value to shared environment state. """ set_nested_dict_safely(self.environment, ["actuator", "desired", variable], value, self.lock)