Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: pip install pytest pytest-cov python-coveralls coverage flake8
run: pip install pytest pytest-cov python-coveralls coverage flake8 pydocstyle

- name: Lint with flake8
run: |
flake8 pyfritzhome --count --show-source --statistics

- name: Run pydocstyle for analysising with Python docstring conventions.
run: pydocstyle

- name: Setup
run: python setup.py install

Expand Down
2 changes: 2 additions & 0 deletions pyfritzhome/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Init file for pyfritzhome."""

from .errors import InvalidError, LoginError
from .fritzhome import Fritzhome
from .fritzhomedevice import FritzhomeDevice
Expand Down
3 changes: 2 additions & 1 deletion pyfritzhome/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
"""A simple CLI tool."""
# -*- coding: utf-8 -*-

from __future__ import print_function
Expand Down Expand Up @@ -165,7 +166,7 @@ def template_apply(fritz, args):


def main(args=None):
"""The main function."""
"""Enter the main function of the CLI tool."""
parser = argparse.ArgumentParser(description="Fritz!Box Smarthome CLI tool.")
parser.add_argument(
"-v", action="store_true", dest="verbose", help="be more verbose"
Expand Down
2 changes: 2 additions & 0 deletions pyfritzhome/devicetypes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Init file for the device types."""

from .fritzhomedevicealarm import FritzhomeDeviceAlarm
from .fritzhomedevicebutton import FritzhomeDeviceButton
from .fritzhomedevicepowermeter import FritzhomeDevicePowermeter
Expand Down
1 change: 1 addition & 0 deletions pyfritzhome/devicetypes/fritzhomedevicealarm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The alarm device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down
1 change: 1 addition & 0 deletions pyfritzhome/devicetypes/fritzhomedevicebase.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The base device class."""
# -*- coding: utf-8 -*-

from __future__ import print_function
Expand Down
8 changes: 8 additions & 0 deletions pyfritzhome/devicetypes/fritzhomedeviceblind.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The blind device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down Expand Up @@ -53,22 +54,29 @@ def _update_blind_from_node(self, node):
pass

def get_level(self):
"""Get the blind level."""
return self.level

def get_level_percentage(self):
"""Get the blind level in percentage."""
return self.levelpercentage

def set_level(self, level):
"""Set the blind level."""
self._fritz.set_level(self.ain, level)

def set_level_percentage(self, levelpercentage):
"""Set the blind level in percentage."""
self._fritz.set_level_percentage(self.ain, levelpercentage)

def set_blind_open(self):
"""Open the blind."""
self._fritz.set_blind_open(self.ain)

def set_blind_close(self):
"""Close the blind."""
self._fritz.set_blind_close(self.ain)

def set_blind_stop(self):
"""Stop the blind."""
self._fritz.set_blind_stop(self.ain)
5 changes: 5 additions & 0 deletions pyfritzhome/devicetypes/fritzhomedevicebutton.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The button device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down Expand Up @@ -41,6 +42,7 @@ def _update_button_from_node(self, node):
pass

def get_button_by_ain(self, ain):
"""Return the button by AIN."""
return self.buttons[ain]


Expand All @@ -53,6 +55,7 @@ class FritzhomeButton(object):
last_pressed = None

def __init__(self, node=None):
"""Create a button object."""
if node is not None:
self._update_from_node(node)

Expand All @@ -67,7 +70,9 @@ def _update_from_node(self, node):
pass

def get_node_value(self, elem, node):
"""Get the node value."""
return elem.findtext(node)

def get_node_value_as_int(self, elem, node) -> int:
"""Get the node value as integer."""
return int(self.get_node_value(elem, node))
3 changes: 3 additions & 0 deletions pyfritzhome/devicetypes/fritzhomedevicefeatures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""The feature list class."""
from enum import IntFlag


class FritzhomeDeviceFeatures(IntFlag):
"""The feature list class."""

ALARM = 0x0010
UNKNOWN = 0x0020
BUTTON = 0x0020
Expand Down
1 change: 1 addition & 0 deletions pyfritzhome/devicetypes/fritzhomedevicelightbulb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The light bulb device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down
3 changes: 2 additions & 1 deletion pyfritzhome/devicetypes/fritzhomedevicepowermeter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The powermeter device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down Expand Up @@ -49,7 +50,7 @@ def _update_powermeter_from_node(self, node):
self.current = None

def get_switch_power(self):
"""The switch state."""
"""Get the switch state."""
return self._fritz.get_switch_power(self.ain)

def get_switch_energy(self):
Expand Down
1 change: 1 addition & 0 deletions pyfritzhome/devicetypes/fritzhomedevicerepeater.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The repeater device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down
1 change: 1 addition & 0 deletions pyfritzhome/devicetypes/fritzhomedeviceswitch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The switch device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down
1 change: 1 addition & 0 deletions pyfritzhome/devicetypes/fritzhomedevicetemperature.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The temperature device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down
1 change: 1 addition & 0 deletions pyfritzhome/devicetypes/fritzhomedevicethermostat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The thermostat device class."""
# -*- coding: utf-8 -*-

import logging
Expand Down
6 changes: 6 additions & 0 deletions pyfritzhome/devicetypes/fritzhomeentitybase.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The entity base class."""
# -*- coding: utf-8 -*-

from __future__ import print_function
Expand All @@ -19,6 +20,7 @@ class FritzhomeEntityBase(ABC):
_functionsbitmask = None

def __init__(self, fritz=None, node=None):
"""Create an entity base object."""
if fritz is not None:
self._fritz = fritz
if node is not None:
Expand All @@ -44,13 +46,17 @@ def _update_from_node(self, node):
# XML Helpers

def get_node_value(self, elem, node):
"""Get the node value."""
return elem.findtext(node)

def get_node_value_as_int(self, elem, node) -> int:
"""Get the node value as integer."""
return int(self.get_node_value(elem, node))

def get_node_value_as_int_as_bool(self, elem, node) -> bool:
"""Get the node value as boolean."""
return bool(self.get_node_value_as_int(elem, node))

def get_temp_from_node(self, elem, node):
"""Get the node temp value as float."""
return float(self.get_node_value(elem, node)) / 2
1 change: 1 addition & 0 deletions pyfritzhome/devicetypes/fritzhometemplate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The template class."""
# -*- coding: utf-8 -*-

import logging
Expand Down
9 changes: 9 additions & 0 deletions pyfritzhome/errors.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
"""Project specific exceptions."""


class LoginError(Exception):
"""The LoginError Exception."""

def __init__(self, user):
"""Initialize the an loginError."""
self.user = user

def __str__(self):
"""Return the error."""
return 'login for user="{}" failed'.format(self.user)


class InvalidError(Exception):
"""The InvalidError Exception."""

pass
11 changes: 9 additions & 2 deletions pyfritzhome/fritzhome.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The main fritzhome handling class."""
# -*- coding: utf-8 -*-

from __future__ import print_function
Expand Down Expand Up @@ -26,6 +27,7 @@ class Fritzhome(object):
_templates: Dict[str, FritzhomeTemplate] = None

def __init__(self, host, user, password, ssl_verify=True):
"""Create a fritzhome object."""
self._host = host
self._user = user
self._password = password
Expand Down Expand Up @@ -125,6 +127,7 @@ def get_prefixed_host(self):
return "http://" + host

def update_devices(self):
"""Update the device."""
_LOGGER.info("Updating Devices ...")
if self._devices is None:
self._devices = {}
Expand Down Expand Up @@ -338,18 +341,21 @@ def _set_blind_state(self, ain, state):
self._aha_request("setblind", ain=ain, param={"target": state})

def set_blind_open(self, ain):
"""Set the blind state to open."""
self._set_blind_state(ain, "open")

def set_blind_close(self, ain):
"""Set the blind state to close."""
self._set_blind_state(ain, "close")

def set_blind_stop(self, ain):
"""Set the blind state to stop."""
self._set_blind_state(ain, "stop")

# Template-related commands

def has_templates(self):
"""Check if the Fritz!Box supports smarthome templates"""
"""Check if the Fritz!Box supports smarthome templates."""
plain = self._aha_request("gettemplatelistinfos")
try:
ElementTree.fromstring(plain)
Expand All @@ -358,6 +364,7 @@ def has_templates(self):
return True

def update_templates(self):
"""Update the template."""
_LOGGER.info("Updating Templates ...")
if self._templates is None:
self._templates = {}
Expand Down Expand Up @@ -393,5 +400,5 @@ def get_template_by_ain(self, ain):
return self.get_templates_as_dict()[ain]

def apply_template(self, ain):
"""Applies a template."""
"""Appliy a template."""
self._aha_request("applytemplate", ain=ain)
3 changes: 3 additions & 0 deletions pyfritzhome/fritzhomedevice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Toplevel device for pyfritzhome."""

# -*- coding: utf-8 -*-

from .devicetypes import FritzhomeTemplate # noqa: F401
Expand Down Expand Up @@ -28,6 +30,7 @@ class FritzhomeDevice(
"""The Fritzhome Device class."""

def __init__(self, fritz=None, node=None):
"""Create a device object."""
super().__init__(fritz, node)

def _update_from_node(self, node):
Expand Down
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ omit =
*/doc/*

[pep257]
ignore = D100,D101,D102,D103,D104,D105,D203,D204
ignore = D203
match-dir = pyfritzhome/*

[pydocstyle]
ignore = D203,D213
match-dir = pyfritzhome/*
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""The setup of the project."""

# -*- coding: utf-8 -*-

from setuptools import setup
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Init file for the tests."""