-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(re-)added pyvlx object. (re-)implemented old scene logic
- Loading branch information
1 parent
a317407
commit b15713e
Showing
15 changed files
with
202 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
config: | ||
host: "192.168.2.127" | ||
host: "192.168.2.102" | ||
password: "velux123" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
"""Module for accessing KLF 200 gateway with python.""" | ||
|
||
# flake8: noqa | ||
from .pyvlx import PyVLX | ||
from .exception import PyVLXException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
"""Module for configuration.""" | ||
|
||
import yaml | ||
|
||
from .exception import PyVLXException | ||
|
||
|
||
# pylint: disable=too-few-public-methods, too-many-arguments | ||
class Config: | ||
"""Class for Configuration.""" | ||
"""Object for configuration.""" | ||
|
||
# pylint: disable=too-few-public-methods | ||
DEFAULT_PORT = 51200 | ||
|
||
def __init__(self, host, password, port=51200): | ||
"""Initialize configuration.""" | ||
self.port = port | ||
def __init__(self, pyvlx, path=None, host=None, password=None, port=None): | ||
"""Initialize Config class.""" | ||
self.pyvlx = pyvlx | ||
self.host = host | ||
self.password = password | ||
self.port = port or self.DEFAULT_PORT | ||
if path is not None: | ||
self.read_config(path) | ||
|
||
def read_config(self, path): | ||
"""Read configuration file.""" | ||
self.pyvlx.logger.info('Reading config file: ', path) | ||
try: | ||
with open(path, 'r') as filehandle: | ||
doc = yaml.load(filehandle) | ||
self.test_configuration(doc, path) | ||
self.host = doc['config']['host'] | ||
self.password = doc['config']['password'] | ||
if 'port' in doc['config']: | ||
self.port = doc['config']['port'] | ||
except FileNotFoundError as ex: | ||
raise PyVLXException('file does not exist: {0}'.format(ex)) | ||
|
||
@staticmethod | ||
def test_configuration(doc, path): | ||
"""Test if configuration file is sane.""" | ||
if 'config' not in doc: | ||
raise PyVLXException('no element config found in: {0}'.format(path)) | ||
if 'host' not in doc['config']: | ||
raise PyVLXException('no element host found in: {0}'.format(path)) | ||
if 'password' not in doc['config']: | ||
raise PyVLXException('no element password found in: {0}'.format(path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
"""Helper module for Node objects.""" | ||
from .const import NodeTypeWithSubtype | ||
|
||
|
||
def convert_frame_to_node(frame): | ||
|
||
"""Convert FrameGet[All]Node[s]InformationNotification into Node object.""" | ||
if frame.node_type == NodeTypeWithSubtype.WINDOW_OPENER_WITH_RAIN_SENSOR: | ||
return "WINDOW" | ||
|
||
print("{} not implemented", format(frame.node_type)) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
Module for PyVLX object. | ||
PyVLX is an asynchronous library for connecting to | ||
a VELUX KLF 200 device for controlling window openers | ||
and roller shutters. | ||
""" | ||
import logging | ||
import asyncio | ||
from .config import Config | ||
from .connection import Connection | ||
from .login import Login | ||
from .exception import PyVLXException | ||
# from .devices import Devices | ||
from .scene_list import SceneList | ||
|
||
|
||
class PyVLX: | ||
"""Class for PyVLX.""" | ||
|
||
# pylint: disable=too-many-arguments | ||
|
||
def __init__(self, path=None, host=None, password=None, log_frames=False, loop=None): | ||
"""Initialize PyVLX class.""" | ||
self.loop = loop or asyncio.get_event_loop() | ||
self.logger = logging.getLogger('pyvlx.log') | ||
self.config = Config(self, path, host, password) | ||
self.connection = Connection(loop=self.loop, config=self.config) | ||
if log_frames: | ||
self.connection.register_frame_received_cb(self.log_frame) | ||
# self.devices = Devices(self) | ||
self.scenes = SceneList(self) | ||
|
||
async def connect(self): | ||
"""Connect to KLF 200.""" | ||
await self.connection.connect() | ||
login = Login(connection=self.connection, password=self.config.password) | ||
await login.do_api_call() | ||
if not login.success: | ||
raise PyVLXException("Unable to login") | ||
|
||
async def disconnect(self): | ||
"""Disconnect from KLF 200.""" | ||
self.connection.disconnect() | ||
|
||
async def load_devices(self): | ||
"""Load devices from KLF 200.""" | ||
# await self.devices.load() | ||
pass | ||
|
||
async def load_scenes(self): | ||
"""Load scenes from KLF 200.""" | ||
await self.scenes.load() | ||
|
||
async def log_frame(self, frame): | ||
"""Log frame to logger.""" | ||
self.logger.warning("%s", frame) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Module for scene.""" | ||
from pyvlx.activate_scene import ActivateScene | ||
|
||
|
||
class Scene: | ||
"""Object for scene.""" | ||
|
||
def __init__(self, pyvlx, scene_id, name): | ||
"""Initialize Scene object.""" | ||
self.pyvlx = pyvlx | ||
self.scene_id = scene_id | ||
self.name = name | ||
|
||
async def run(self): | ||
"""Run scene.""" | ||
activate_scene = ActivateScene(connection=self.pyvlx.connection, scene_id=self.scene_id) | ||
await activate_scene.do_api_call() | ||
|
||
def __str__(self): | ||
"""Return object as readable string.""" | ||
return '<Scene name="{0}" ' \ | ||
'id="{1}" />' \ | ||
.format( | ||
self.name, | ||
self.scene_id) | ||
|
||
def __eq__(self, other): | ||
"""Equal operator.""" | ||
return self.__dict__ == other.__dict__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
config: | ||
host: "192.168.2.127" | ||
password: "velux123" | ||
port: 1234 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.