def __init__(self, sensor_name, ecobee_service=None, prediction_threshold=0.6): Resource.__init__(self, "OccupancySensor_{}".format( sensor_name), ["occupancy", "predicted_occupancy", "temperature"]) self.sensor_name = sensor_name self.ecobee_service = ecobee_service if self.ecobee_service is None: # try to grab it from the EcobeeResource def wait_ecobee_service(): self.ecobee_service = Resource.resource( "EcobeeResource").ecobee_service Resource.waitResource("EcobeeResource", wait_ecobee_service) try: wait_ecobee_service() except ResourceNotFoundException: pass self.prediction_resource = OccupancyPredictorResource( self.name, prediction_threshold=prediction_threshold)
def __init__(self, name=None, occupancy_resource=None, prediction_threshold=0.70): if occupancy_resource is None: occupancy_resource = "GlobalOccupancy" if name is None: self.name = "{}_OccuppancyPredictorResource".format( occupancy_resource) else: self.name = name super().__init__( self.name, power_usage=100, variables=["occupancy_prediction", "occupancy_prediction_raw"]) self.predictors = None self.did_train = False self.runtime_policy = RunIfCanPolicy( conditions=[lambda: not self.did_train]) self.prediction_threshold = prediction_threshold self.occupancy_resource = occupancy_resource self.model_dir = "{}_occupancy_predictor".format(occupancy_resource) Resource.waitResource([occupancy_resource], self.init_predictor) asyncio.get_event_loop().create_task(self.reset_train_counter())
def __init__(self, occupancy_predictor_name=None, power_usage=1750): super().__init__("EcobeeResource", power_usage=power_usage, variables=["occupancy", "setpoint_heat", "setpoint_cool", "temperature", "humidity", "running_program"], priority=RuntimePriority.high) self.subscribe("temperature", lambda v: self.process()) self.subscribe("running_program", lambda v: self.process()) self.occupancy_prediction = False self.occupancy_predictor_name = occupancy_predictor_name self.occupancy_predictor = None config = Resource.resource("ConfigurationResource").config api_key = config["ecobee_apikey"] thermostat_name = config["ecobee_thermostat_name"] self.ecobee_user_preferences = None self.present_users = [] if "ecobee_user_preferences" in config: self.ecobee_user_preferences = config["ecobee_user_preferences"] self.ecobee_service = Ecobee(thermostat_name, api_key) self.poller = resource_poll(self.poll_func, MINS(3), is_coroutine=True) def wait_resources(): self.occupancy_predictor = Resource.resource( self.occupancy_predictor_name) self.occupancy_predictor.subscribe( "occupancy_prediction", self.occupancy_changed) Resource.resource("SolarPower").subscribe( "current_power", self.solar_power_changed) self.night_time_resource = Resource.resource("NightTime") Resource.waitResource( [self.occupancy_predictor_name, "SolarPower", "NightTime"], wait_resources) def wait_ble_resource(): Resource.resource("BleUserResource").subscribe( "present_users", self.ble_present_users_changed) Resource.waitResource("BleUserResource", wait_ble_resource) self.ecobee_can_run_hold = False self.setpoint_cool = None self.setpoint_heat = None
def __init__(self, resource, broker, override_name=None, retain_msgs=False, qos=0, whitelist_variables=None, blacklist_variables=None, quiet=True, **kwargs): super().__init__(name=override_name, broker=broker, **kwargs) self.resource = resource self.whitelist_variables = whitelist_variables self.blacklist_variables = blacklist_variables self.retain = retain_msgs self.qos = qos self.override_name = override_name self.quiet = quiet if isinstance(resource, str): try: self.resource = Resource.resource(resource) self._subscribe() except ResourceNotFoundException: def wait_resource(): self.resource = Resource.resource(resource) self._subscribe() Resource.waitResource(resource, wait_resource) elif isinstance(resource, Resource): self._subscribe() else: raise ValueError("Invalid resource type: {}".format( resource.__class__.__name__)) self.whitelist_variables = whitelist_variables self.blacklist_variables = blacklist_variables self.retain = retain_msgs self.qos = qos self.override_name = override_name self.connected = False
def __init__(self, linked_device_name, conditions=None, or_conditions=None): super().__init__(policy=RuntimePolicies.link_device_policy, conditions=conditions, or_conditions=or_conditions) self.linked_device_running = None def wait_resource(): self.linked_device_running = gr( linked_device_name).subscribe2("running") try: gr(linked_device_name) wait_resource() except ResourceNotFoundException: Resource.waitResource(linked_device_name, wait_resource)
def __init__(self, name="DeviceManager", max_power_budget=0, power_source=None, debug=False): """ max_power_budget is to be used to define the max power budget when there is no solar system (ie battery system, or pure-grid system). power_source must have the "available_power" property unless max power_budget is set. available_power is max_power_budget until power_source updates. """ super().__init__(name, ["total_power", "running_devices", "capacity", "total_capacity"]) if power_source is None: power_source = ["SolarPower"] if isinstance(power_source, str): power_source = [power_source] power_sources = power_source self.running_devices = [] self.managed_devices = [] self.ignored_devices = [] self.max_power_budget = max_power_budget self.time_of_use_mode = None self.debug = debug self.power_sources = None if not max_power_budget: self.power_sources = ResourceRequires( power_sources, lambda rsrcs: True) def wait_time_of_use(): gr("TimeOfUse").subscribe("mode", self.time_of_use_changed) try: wait_time_of_use() except ResourceNotFoundException: Resource.waitResource("TimeOfUse", wait_time_of_use) self.poller = resource_poll(self.process_managed_devices, MINS(1))