diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ffe98ea..4ad0a49 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/pyfritzhome/__init__.py b/pyfritzhome/__init__.py index 08a7be1..d72d20c 100644 --- a/pyfritzhome/__init__.py +++ b/pyfritzhome/__init__.py @@ -1,3 +1,5 @@ +"""Init file for pyfritzhome.""" + from .errors import InvalidError, LoginError from .fritzhome import Fritzhome from .fritzhomedevice import FritzhomeDevice diff --git a/pyfritzhome/cli.py b/pyfritzhome/cli.py index 553216a..59628ee 100644 --- a/pyfritzhome/cli.py +++ b/pyfritzhome/cli.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +"""A simple CLI tool.""" # -*- coding: utf-8 -*- from __future__ import print_function @@ -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" diff --git a/pyfritzhome/devicetypes/__init__.py b/pyfritzhome/devicetypes/__init__.py index 8a980d8..d698551 100644 --- a/pyfritzhome/devicetypes/__init__.py +++ b/pyfritzhome/devicetypes/__init__.py @@ -1,3 +1,5 @@ +"""Init file for the device types.""" + from .fritzhomedevicealarm import FritzhomeDeviceAlarm from .fritzhomedevicebutton import FritzhomeDeviceButton from .fritzhomedevicepowermeter import FritzhomeDevicePowermeter diff --git a/pyfritzhome/devicetypes/fritzhomedevicealarm.py b/pyfritzhome/devicetypes/fritzhomedevicealarm.py index f8884f3..dccca14 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicealarm.py +++ b/pyfritzhome/devicetypes/fritzhomedevicealarm.py @@ -1,3 +1,4 @@ +"""The alarm device class.""" # -*- coding: utf-8 -*- import logging diff --git a/pyfritzhome/devicetypes/fritzhomedevicebase.py b/pyfritzhome/devicetypes/fritzhomedevicebase.py index e5cff34..5cd0f43 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicebase.py +++ b/pyfritzhome/devicetypes/fritzhomedevicebase.py @@ -1,3 +1,4 @@ +"""The base device class.""" # -*- coding: utf-8 -*- from __future__ import print_function diff --git a/pyfritzhome/devicetypes/fritzhomedeviceblind.py b/pyfritzhome/devicetypes/fritzhomedeviceblind.py index d7e27d4..26c6b4a 100644 --- a/pyfritzhome/devicetypes/fritzhomedeviceblind.py +++ b/pyfritzhome/devicetypes/fritzhomedeviceblind.py @@ -1,3 +1,4 @@ +"""The blind device class.""" # -*- coding: utf-8 -*- import logging @@ -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) diff --git a/pyfritzhome/devicetypes/fritzhomedevicebutton.py b/pyfritzhome/devicetypes/fritzhomedevicebutton.py index 71b8630..4c4d0f4 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicebutton.py +++ b/pyfritzhome/devicetypes/fritzhomedevicebutton.py @@ -1,3 +1,4 @@ +"""The button device class.""" # -*- coding: utf-8 -*- import logging @@ -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] @@ -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) @@ -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)) diff --git a/pyfritzhome/devicetypes/fritzhomedevicefeatures.py b/pyfritzhome/devicetypes/fritzhomedevicefeatures.py index b7e0398..8b0a0f4 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicefeatures.py +++ b/pyfritzhome/devicetypes/fritzhomedevicefeatures.py @@ -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 diff --git a/pyfritzhome/devicetypes/fritzhomedevicelightbulb.py b/pyfritzhome/devicetypes/fritzhomedevicelightbulb.py index 742bedb..8bccbd9 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicelightbulb.py +++ b/pyfritzhome/devicetypes/fritzhomedevicelightbulb.py @@ -1,3 +1,4 @@ +"""The light bulb device class.""" # -*- coding: utf-8 -*- import logging diff --git a/pyfritzhome/devicetypes/fritzhomedevicepowermeter.py b/pyfritzhome/devicetypes/fritzhomedevicepowermeter.py index b6ec52d..fbee6d4 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicepowermeter.py +++ b/pyfritzhome/devicetypes/fritzhomedevicepowermeter.py @@ -1,3 +1,4 @@ +"""The powermeter device class.""" # -*- coding: utf-8 -*- import logging @@ -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): diff --git a/pyfritzhome/devicetypes/fritzhomedevicerepeater.py b/pyfritzhome/devicetypes/fritzhomedevicerepeater.py index a57cdca..6642a71 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicerepeater.py +++ b/pyfritzhome/devicetypes/fritzhomedevicerepeater.py @@ -1,3 +1,4 @@ +"""The repeater device class.""" # -*- coding: utf-8 -*- import logging diff --git a/pyfritzhome/devicetypes/fritzhomedeviceswitch.py b/pyfritzhome/devicetypes/fritzhomedeviceswitch.py index 80a3603..66c4165 100644 --- a/pyfritzhome/devicetypes/fritzhomedeviceswitch.py +++ b/pyfritzhome/devicetypes/fritzhomedeviceswitch.py @@ -1,3 +1,4 @@ +"""The switch device class.""" # -*- coding: utf-8 -*- import logging diff --git a/pyfritzhome/devicetypes/fritzhomedevicetemperature.py b/pyfritzhome/devicetypes/fritzhomedevicetemperature.py index b0e7d40..5b241a9 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicetemperature.py +++ b/pyfritzhome/devicetypes/fritzhomedevicetemperature.py @@ -1,3 +1,4 @@ +"""The temperature device class.""" # -*- coding: utf-8 -*- import logging diff --git a/pyfritzhome/devicetypes/fritzhomedevicethermostat.py b/pyfritzhome/devicetypes/fritzhomedevicethermostat.py index 5309a36..a8c8864 100644 --- a/pyfritzhome/devicetypes/fritzhomedevicethermostat.py +++ b/pyfritzhome/devicetypes/fritzhomedevicethermostat.py @@ -1,3 +1,4 @@ +"""The thermostat device class.""" # -*- coding: utf-8 -*- import logging diff --git a/pyfritzhome/devicetypes/fritzhomeentitybase.py b/pyfritzhome/devicetypes/fritzhomeentitybase.py index d236cf6..274b5d1 100644 --- a/pyfritzhome/devicetypes/fritzhomeentitybase.py +++ b/pyfritzhome/devicetypes/fritzhomeentitybase.py @@ -1,3 +1,4 @@ +"""The entity base class.""" # -*- coding: utf-8 -*- from __future__ import print_function @@ -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: @@ -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 diff --git a/pyfritzhome/devicetypes/fritzhometemplate.py b/pyfritzhome/devicetypes/fritzhometemplate.py index 362860f..88dff3d 100644 --- a/pyfritzhome/devicetypes/fritzhometemplate.py +++ b/pyfritzhome/devicetypes/fritzhometemplate.py @@ -1,3 +1,4 @@ +"""The template class.""" # -*- coding: utf-8 -*- import logging diff --git a/pyfritzhome/errors.py b/pyfritzhome/errors.py index e0a0ece..6633ea8 100644 --- a/pyfritzhome/errors.py +++ b/pyfritzhome/errors.py @@ -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 diff --git a/pyfritzhome/fritzhome.py b/pyfritzhome/fritzhome.py index e90d43c..4192ce7 100644 --- a/pyfritzhome/fritzhome.py +++ b/pyfritzhome/fritzhome.py @@ -1,3 +1,4 @@ +"""The main fritzhome handling class.""" # -*- coding: utf-8 -*- from __future__ import print_function @@ -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 @@ -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 = {} @@ -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) @@ -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 = {} @@ -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) diff --git a/pyfritzhome/fritzhomedevice.py b/pyfritzhome/fritzhomedevice.py index 28ec9c8..e4d6889 100644 --- a/pyfritzhome/fritzhomedevice.py +++ b/pyfritzhome/fritzhomedevice.py @@ -1,3 +1,5 @@ +"""Toplevel device for pyfritzhome.""" + # -*- coding: utf-8 -*- from .devicetypes import FritzhomeTemplate # noqa: F401 @@ -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): diff --git a/setup.cfg b/setup.cfg index 75fffb5..5d223f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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/* diff --git a/setup.py b/setup.py index b694e6e..671c894 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +"""The setup of the project.""" + # -*- coding: utf-8 -*- from setuptools import setup diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..aaa5d9f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1 @@ +"""Init file for the tests."""