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")
def process(self): t = datetime.now().time() try: current_time_resource = Resource.resource("CurrentTimeResource") has_time = current_time_resource.getValue("datetime") if has_time is not None: t = has_time.time() except ResourceNotFoundException: pass except Exception as e: print("night_time: another bad exception: {}".format(e)) self.isNightTime = ((t > self.location.sunset().time() and t <= time(23, 59, 59)) or (t >= time(0) and t < self.location.sunrise().time())) self.sunset = self.location.sunset().time() self.sunrise = self.location.sunrise().time() self.setValue("nightTime", self.isNightTime) self.setValue("night_time", self.isNightTime) self.setValue("sunset", str(self.location.sunset().time())) self.setValue("sunrise", str(self.location.sunrise().time()))
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.__init__(self, "TimeOfUse", ["mode", "schedule"]) try: config = Resource.resource("ConfigurationResource").config self.winter_schedule = config["time_of_use_schedule"]["winter"] self.summer_schedule = config["time_of_use_schedule"]["summer"] self.poller = resource_poll(self.update_schedule, MINS(1)) except ResourceNotFoundException: print("TimeOfUse: No configuration resource!")
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 get_current_datetime(utc=False): try: cur_time_resource = Resource.resource("CurrentTimeResource") if utc: u = cur_time_resource.get_value("datetime_utc").replace( tzinfo=pytz.utc) return u return cur_time_resource.get_value("datetime") except ResourceNotFoundException: if utc: u = datetime.utcnow().replace(tzinfo=pytz.utc) return u return datetime.now()
def wait_resource(): self.resource = Resource.resource(resource) self._subscribe()
def wait_ble_resource(): Resource.resource("BleUserResource").subscribe( "present_users", self.ble_present_users_changed)
def wait_ecobee_service(): self.ecobee_service = Resource.resource( "EcobeeResource").ecobee_service