def __init__(self, name, hammock_instance, poll_rate=2): self.hammock_instance = hammock_instance variables = self.hammock_instance.GET(verify=False).json()["variables"] Resource.__init__(self, name, variables.keys()) self.poller = resource_poll(self.poll_func, MINS(poll_rate))
def __init__(self, name="NightTime", lat=None, lon=None, timezone="US/Pacific"): Resource.__init__( self, name, ["nightTime", "night_time", "sunset", "sunrise"]) if lat is None or lon is None: try: config = get_resource("ConfigurationResource") lat = config.get_value("latitude") lon = config.get_value("longitude") except ResourceNotFoundException: raise Exception( "NightTime requires lat/lon set or ConfigurationResource") if lat is None or lon is None: raise Exception( "NightTime: missing latitude/longitude in ConfigurationResource") print("using lat/lon: {}, {}".format(lat, lon)) self.location = Location() self.location.latitude = float(lat) self.location.longitude = float(lon) self.location.timezone = timezone self.process() self.poller = resource_poll(self.process, MINS(1))
def __init__(self, configFileName): Resource.__init__(self, "ConfigurationResource", ["config"]) self.configFile = configFileName self.reload() self.setValue("config", self.config)
def __init__(self, name, broker, variables=None, variable_mqtt_map=None, quiet=True, encoding='utf-8', **kwargs): """ :param variable_mqtt_map - map mqtt messages to local variables. eg. remote_resource = MqttResource("light_switch1", "some.broker.com", ["foo"], {'foo' : 'light_switch1/foo'}) :param topic_conversion_map - map of mqtt topics and conversion functions """ self.encoding = encoding if variables is None: variables = [] if variable_mqtt_map is None: variable_mqtt_map = {} self.quiet = quiet Resource.__init__(self, name, variables, ignore_same_value=False) MqttCommon.__init__(self, name, broker=broker, **kwargs) self.variable_mqtt_map = variable_mqtt_map
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): 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.__init__(self, "weather", [ "temperature", "humidity", "forecast_high", "forecast_low", "forecast_conditions", "condition", "current_observation", "cloud_cover", "forecast_cloud_cover" ]) self.key = get_resource("ConfigurationResource").config["weather_key"] self.lat = get_resource("ConfigurationResource").config["latitude"] self.lon = get_resource("ConfigurationResource").config["longitude"] self.poller = resource_poll(self.poll_func, MINS(15), is_coroutine=True)