Beispiel #1
0
 def init():
     YouTubeController.refresh_token = SecureSettings.get_string(
         "youtube_refresh_token")
     YouTubeController.api = API(
         client_id=SecureSettings.get_string("youtube_client_id"),
         client_secret=SecureSettings.get_string("youtube_client_secret"),
         api_key=SecureSettings.get_string("youtube_api_key"))
Beispiel #2
0
    def get_weather_data(self):
        while True:
            api_key = SecureSettings.get_string("open_weather_map_key")
            url = "http://api.openweathermap.org/data/2.5/group?id=2750947&units=metric&appid=" + api_key
            result = RequestFactory.make_request(url)
            if not result:
                Logger().write(LogVerbosity.Info, "Failed to get weather data")
                return

            data = json.loads(result.decode('utf8'))
            current_temp = data['list'][0]['main']['temp']
            icon = data['list'][0]['weather'][0]['icon'].replace('n', 'd')

            self.background_canvas.itemconfigure(
                self.weather_temp, text=str(round(current_temp, 1)) + "°C")

            image = Image.open(self.base_image_path + "Weather/" + icon +
                               ".png")
            resized = image.resize((140, 140), Image.ANTIALIAS)
            self.background_canvas.weather_icon = ImageTk.PhotoImage(resized)
            self.background_canvas.itemconfigure(
                self.weather_icon_image,
                image=self.background_canvas.weather_icon)

            time.sleep(60 * 30)
Beispiel #3
0
    def on_init(client_name, key):
        Logger().write(LogVerbosity.Info, "Init slave: " + client_name)
        if key != SecureSettings.get_string("master_key"):
            Logger().write(LogVerbosity.Info, "Slave authentication failed")
            disconnect()
            return False

        slave = APIController.slaves.get_slave(client_name)
        if slave is not None:
            if slave.connected:
                Logger().write(
                    LogVerbosity.Info,
                    "Slave " + str(client_name) + " connected twice?")
                disconnect()
                return False
            else:
                Logger().write(LogVerbosity.Info,
                               "Slave " + str(client_name) + " reconnected")
                slave.reconnect(request.sid)
                APIController.slaves.changed()
                return True

        client = WebsocketClient(request.sid, current_time())
        client.authenticated = True
        APIController.slaves.add_slave(
            SlaveClient(APIController.next_id(), client_name, client))
        return client.authenticated
Beispiel #4
0
    def validate(client_id, p, ip, user_agent):
        if APIController.get_salted(p) == SecureSettings.get_string(
                "api_password"):
            client_key = APIController.get_salted(client_id)
            session_key = AuthController.generate_session_key()
            Database().add_client(client_key, session_key, ip, user_agent)
            return True, session_key

        return False, None
Beispiel #5
0
 def __init__(self):
     self.api = Toon(SecureSettings.get_string("eneco_username"), SecureSettings.get_string("eneco_pw"), SecureSettings.get_string("toon_consumer_id"), SecureSettings.get_string("toon_consumer_secret"))
Beispiel #6
0
 def get_salt():
     if APIController.salt is None:
         APIController.salt = SecureSettings.get_string("api_salt").encode()
     return APIController.salt
Beispiel #7
0
 def initialize(self):
     Logger().write(LogVerbosity.Info, "Connected to master")
     self.emit("init", Settings.get_string("name"), SecureSettings.get_string("master_key"), self.handle_init_response)
Beispiel #8
0
    def init(self):
        if self.initialized:
            Logger().write(LogVerbosity.Info, "already init")
            return

        if sys.platform != "linux" and sys.platform != "linux2":
            Logger().write(LogVerbosity.Info, "Lighting: Not initializing, no coap client available on windows")
            self.initialized = True
            self.tradfri_state.update_group(DeviceGroup(1, "Test group", True, 128, 6))
            self.tradfri_state.update_group(DeviceGroup(2, "Test group 2", False, 18, 6))
            return

        if current_time() - self.last_init < 5000:
            Logger().write(LogVerbosity.Info, "Tried initialization less than 5s ago")
            return

        Logger().write(LogVerbosity.All, "Start LightManager init")
        self.enabled = True
        if not self.initialized:
            ip = Settings.get_string("tradfri_hub_ip")
            identity = Database().get_stat_string("LightingId")
            key = Database().get_stat_string("LightingKey")

            if identity is None or key is None:
                Logger().write(LogVerbosity.Info, "Lighting: No identity/key found, going to generate new")
                # We don't have all information to connect, reset and start from scratch
                Database().remove_stat("LightingId")
                Database().remove_stat("LightingKey")
                key = None

                identity = uuid.uuid4().hex
                Database().update_stat("LightingId", identity)  # Generate and save a new id
                self.api_factory = APIFactory(host=ip, psk_id=identity)
            else:
                self.api_factory = APIFactory(host=ip, psk_id=identity, psk=key)

            self.api = self.api_factory.request
            self.gateway = Gateway()

            if key is None:
                try:
                    security_code = SecureSettings.get_string("tradfri_hub_code")  # the code at the bottom of the hub
                    key = self.api_factory.generate_psk(security_code)
                    Database().update_stat("LightingKey", key)  # Save the new key
                    Logger().write(LogVerbosity.Info, "Lighting: New key retrieved")
                except Exception as e:
                    Logger().write_error(e, "Unhandled exception")
                    return
            else:
                Logger().write(LogVerbosity.Info, "Lighting: Previously saved key found")

            try:
                self.initialized = True
                groups = self.get_device_groups()
                for group in groups:
                    self.tradfri_state.update_group(group)
            except Exception as e:
                Logger().write(LogVerbosity.Info, "Failed to init tradfri, clearing previous key to try generate new")
                self.initialized = False
                Database().remove_stat("LightingId")
                Database().remove_stat("LightingKey")
                Logger().write_error(e, "Failed to get groups from hub")