Пример #1
0
    def poll(self):
        while True:
            try:
                if self.predictor is None:
                    yield from asyncio.sleep(MINS(5))
                    continue

                predicted_temperature = self.predictor.predict()

                print(
                    "predicted temperature: {}".format(predicted_temperature))
                print("actual temperature: {}".format(
                    gr(self.temp1).get_value("temperature")))

                self.set_value("temperature", predicted_temperature)

                predicted_solar = self.predict_solar()

                print("predicted solar power: {}".format(predicted_solar))
                print("actual solar power: {}".format(
                    gr(self.solar).get_value("current_power")))

                self.set_value("solar_power", predicted_solar)

            except AttributeError as ae:
                print("{} - Error. don't have a predictor yet? {}".format(
                    self.name, ae))
                import sys
                import traceback
                exc_type, exc_value, exc_traceback = sys.exc_info()
                traceback.print_tb(exc_traceback, limit=12, file=sys.stdout)
                traceback.print_exception(exc_type,
                                          exc_value,
                                          exc_traceback,
                                          limit=12,
                                          file=sys.stdout)
                pass

            except Exception as ex:
                import sys
                import traceback
                exc_type, exc_value, exc_traceback = sys.exc_info()
                traceback.print_tb(exc_traceback, limit=6, file=sys.stdout)
                traceback.print_exception(exc_type,
                                          exc_value,
                                          exc_traceback,
                                          limit=6,
                                          file=sys.stdout)

            yield from asyncio.sleep(MINS(5))
Пример #2
0
    def full_login(self):
        while True:
            if self.username is None:
                self.username = gr(
                    "ConfigurationResource").config["sonoff_username"]
            if self.password is None:
                self.password = gr(
                    "ConfigurationResource").config["sonoff_password"]
            if self.region is None:
                self.region = gr("ConfigurationResource").config.get(
                    "sonoff_region", "us")

            self.s = sonoff.Sonoff(self.username, self.password, self.region)

            yield from self.update()

            yield from asyncio.sleep(HOURS(8))
Пример #3
0
    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)
Пример #4
0
    def predict_solar(self, t=None):

        if t is None:
            t = get_current_datetime()

        weather = gr("weather")

        forecast = weather.get_standard_forecast(t)
        cloud_cover = forecast["forecast_cloud_cover"]

        solar_insolation = gr("SolarInsolation")

        radiation_forecast = solar_insolation.get_solar_radiation(
            t.astimezone(pytz.utc))

        return self.solar_predictor.predict(replace_features=[
            ReplaceFeatureColumn("solar_insolation", radiation_forecast),
            ReplaceFeatureColumn("weather", forecast)
        ])
Пример #5
0
        def wait_occupancy(gr):
            self.occupancy_resource = gr(occupancy_resource_name)
            self.conditions.append(self.can_run)

            if self.occupancy_resource.hasProperty(occupancy_property):
                self.occupancy = self.occupancy_resource.subscribe2(
                    occupancy_property)
            else:
                raise ValueError(
                    """resource {} does not {} property""".format(
                        occupancy_resource_name, occupancy_property))
Пример #6
0
    def predict_temperature(self, t=None):
        if t is None:
            t = get_current_datetime()

        weather = gr("weather")

        forecast = weather.get_forecast(t)

        cloud_cover = forecast['forecast_cloud_cover']
        weather_temperature = forecast['forecast_high']

        solar_insolation = gr("SolarInsolation")

        radiation_forecast = solar_insolation.get_solar_radiation(
            t.astimezone(pytz.utc))

        solar_power_prediction = self.predict_solar(t)

        return self.solar_predictor.predict(replace_features=[
            ReplaceFeatureColumn("solar_insolation", radiation_forecast),
            ReplaceFeatureColumn("weather_cloud_cover", cloud_cover),
            ReplaceFeatureColumn("weather_temperature", weather_temperature),
            ReplaceFeatureColumn("solar_power", solar_power_prediction)
        ])
Пример #7
0
 def wait_time_of_use():
     gr("TimeOfUse").subscribe("mode", self.time_of_use_changed)
Пример #8
0
        def wait_resource(gr):
            self.temperature = gr(sensor_name).subscribe2("temperature")

            self.conditions.append(self.can_run)
Пример #9
0
 def wait_resource():
     self.linked_device_running = gr(
         linked_device_name).subscribe2("running")