Skip to content

Commit

Permalink
Add type hints to __main__.py (#463)
Browse files Browse the repository at this point in the history
* Finalise adding type hints

* Remove type hint not needed

* Put back tox.ini

* Remove blank line

* Revert all changes
  • Loading branch information
ggravlingen authored Mar 19, 2022
1 parent a54d45d commit 9e37a9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 315 deletions.
290 changes: 0 additions & 290 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,295 +20,5 @@ warn_unreachable = true
plugins = pydantic.mypy
strict = True

[mypy-pytradfri.*]
check_untyped_defs = false
disallow_incomplete_defs = false
disallow_subclassing_any = false
disallow_untyped_calls = false
disallow_untyped_decorators = false
disallow_untyped_defs = false
no_implicit_optional = false
warn_return_any = false
warn_unreachable = false

[mypy-tests.*]
ignore_errors = true

# --- strict typing ---
# one entry pr file.
# when a directory is converted, file entries are replaced by directory entry
# when the library is converted, the above entry will be replaced (strict is demanded)
[mypy-pytradfri.command]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.const]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.error]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.api.__init__]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.api.aiocoap_api]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.api.libcoap_api]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.base_controller]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.color]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.resource]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.__init__]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.blind]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.blind_control]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.socket]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.socket_control]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.air_purifier]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.air_purifier_control]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.signal_repeater]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.signal_repeater_control]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.light]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.device.light_control]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.group]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.mood]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.util]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.smart_task]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-pytradfri.gateway]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
48 changes: 23 additions & 25 deletions pytradfri/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""Provide a CLI for Tradfri."""
from __future__ import annotations

import argparse
import logging
from pprint import pprint
import uuid

from pytradfri.api.libcoap_api import APIFactory
from pytradfri.device import Device
from pytradfri.error import PytradfriError
from pytradfri.group import Group
from pytradfri.util import load_json, save_json

from .command import Command
Expand All @@ -14,9 +18,21 @@
CONFIG_FILE = "tradfri_standalone_psk.conf"


def main(org_args):
"""Run main."""
global devices, homekit_id, light, api, lights, gateway, groups, moods, tasks, dump_devices, dump_all # pylint: disable=global-variable-undefined, invalid-name
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)

parser = argparse.ArgumentParser()
parser.add_argument(
"host", metavar="IP", type=str, help="IP Address of your Tradfri gateway"
)
parser.add_argument(
"-K",
"--key",
dest="key",
required=False,
help="Security code found on your Tradfri gateway",
)
org_args = parser.parse_args()

if org_args.host not in load_json(CONFIG_FILE) and org_args.key is None:
print(
Expand Down Expand Up @@ -61,15 +77,15 @@ def main(org_args):
devices = api(devices_commands)
lights = [dev for dev in devices if dev.has_light_control]
if lights:
light = lights[0]
light: Device | None = lights[0]
else:
print("No lights found!")
light = None
groups_commands = api(gateway.get_groups())
groups = api(groups_commands)
moods = []
if groups:
group = groups[0]
group: Group | None = groups[0]
for group in groups:
moods_commands = api(group.moods())
group_moods = api(moods_commands)
Expand All @@ -81,7 +97,7 @@ def main(org_args):
tasks = api(tasks_commands)
homekit_id = api(gateway.get_gateway_info()).homekit_id

def dump_all(): # pylint: disable=unused-variable
def dump_all() -> None: # pylint: disable=unused-variable
"""Dump all endpoints."""
endpoints = api(gateway.get_endpoints())

Expand All @@ -95,7 +111,7 @@ def dump_all(): # pylint: disable=unused-variable
print()
print()

def dump_devices(): # pylint: disable=unused-variable
def dump_devices() -> None: # pylint: disable=unused-variable
"""Dump devices."""
pprint([d.raw for d in devices])

Expand All @@ -118,21 +134,3 @@ def dump_devices(): # pylint: disable=unused-variable
print("> tasks")
print("> dump_devices()")
print("> dump_all()")


if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)

parser = argparse.ArgumentParser()
parser.add_argument(
"host", metavar="IP", type=str, help="IP Address of your Tradfri gateway"
)
parser.add_argument(
"-K",
"--key",
dest="key",
required=False,
help="Security code found on your Tradfri gateway",
)
args = parser.parse_args()
main(args)

0 comments on commit 9e37a9b

Please sign in to comment.