def get_peripheral_reported_sensor_value( self, peripheral: str, variable: str ) -> Any: """Gets reported sensor value from shared peripheral state.""" return get_nested_dict_safely( self.peripherals, [peripheral, "sensor", "reported", variable] )
def get_peripheral_desired_actuator_value( self, peripheral: str, variable: str ) -> Any: """Gets desired actuator value from shared peripheral state.""" return get_nested_dict_safely( self.peripherals, [peripheral, "actuator", "desired", variable] )
def publish_environment_variables(self, publish_all: bool = False) -> None: """Publishes environment variables.""" self.logger.debug(f"Publishing {'all' if publish_all else 'changed'} environment variables") # Get environment variables keys = ["reported_sensor_stats", "individual", "instantaneous"] environment_variables = accessors.get_nested_dict_safely( self.state.environment, keys ) # Ensure environment variables is a dict if environment_variables == None: environment_variables = {} # For each value, only publish the ones that have changed. for name, value in environment_variables.items(): if publish_all: self.prev_environment_variables[name] = copy.deepcopy(value) self.pubsub.publish_environment_variable(name, value) elif self.prev_environment_variables.get(name) != value: self.prev_environment_variables[name] = copy.deepcopy(value) self.pubsub.publish_environment_variable(name, value)
def publish_environment_variables(self) -> None: """Publishes environment variables.""" self.logger.debug("Publishing environment variables") # Get environment variables keys = ["reported_sensor_stats", "individual", "instantaneous"] environment_variables = accessors.get_nested_dict_safely( self.state.environment, keys) # Ensure environment variables is a dict if environment_variables == None: environment_variables = {} # Keep a copy of the first set of values (usually None). Why? if self.prev_environment_variables == {}: self.environment_variables = copy.deepcopy(environment_variables) # For each value, only publish the ones that have changed. for name, value in environment_variables.items(): if self.prev_environment_variables.get(name) != value: self.environment_variables[name] = copy.deepcopy(value) self.pubsub.publish_environment_variable(name, value)
def publish(self): if self.iot is None: return # Safely get vars dict vars_dict = get_nested_dict_safely( self.state.environment, ["reported_sensor_stats", "individual", "instantaneous"], ) # Check if vars is empty, if so turn into a dict if vars_dict == None: vars_dict = {} # Keep a copy of the first set of values (usually None). if self.prev_vars is None: self.prev_vars = copy.deepcopy(vars_dict) # for each value, only publish the ones that have changed. for var in vars_dict: if self.prev_vars[var] != vars_dict[var]: self.prev_vars[var] = copy.deepcopy(vars_dict[var]) self.iot.publish_env_var(var, vars_dict[var])
def get_controller_value(self, controller: str, variable: str) -> Any: """Gets controller value from shared controller state.""" return get_nested_dict_safely(self.controllers, [controller, variable])
def get_environment_desired_actuator_value(self, variable: str) -> Any: """Gets desired actuator value from shared environment state.""" return get_nested_dict_safely( self.environment, ["actuator", "desired", variable] )
def get_peripheral_value(self, peripheral: str, variable: str) -> Any: """ Gets peripheral value from shared peripheral state. """ return get_nested_dict_safely(self.peripherals, [peripheral, variable])
def get_environment_reported_sensor_value(self, variable: str) -> Any: """Gets reported sensor value from shared environment state.""" return get_nested_dict_safely( self.environment, ["sensor", "reported", variable] )
def get_peripheral_reported_actuator_value(self, peripheral, variable): """ Gets reported actuator value from shared peripheral state. """ return get_nested_dict_safely( self.peripherals, [peripheral, "actuator", "reported", variable])
def get_peripheral_desired_sensor_value(self, peripheral, variable): """ Gets desired sensor value from shared peripheral state. """ return get_nested_dict_safely( self.peripherals, [peripheral, "sensor", "desired", variable])
def get_environment_reported_actuator_value(self, variable): """ Gets reported actuator value from shared environment state. """ return get_nested_dict_safely(self.environment, ["actuator", "reported", variable])
def get_environment_desired_sensor_value(self, variable): """ Gets desired sensor value from shared environment state. """ return get_nested_dict_safely(self.environment, ["sensor", "desired", variable])