Skip to content

Commit

Permalink
HACS Update - Garbage Collection - #16
Browse files Browse the repository at this point in the history
  • Loading branch information
BeardedTinker committed Sep 3, 2020
1 parent 0f5e701 commit e2f106d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 86 deletions.
11 changes: 6 additions & 5 deletions custom_components/garbage_collection/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import uuid
from datetime import datetime
from typing import Dict

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -46,7 +47,7 @@ def __init__(self, unique_id):
self.errors = {}
self.data_schema = {}

def update_data(self, user_input, step):
def update_data(self, user_input: Dict, step: int):
"""Remove empty fields, and fields that should not be stored in the config."""
self._data.update(user_input)
items = {
Expand All @@ -61,7 +62,7 @@ def update_data(self, user_input, step):
self.name = self._data[CONF_NAME]
del self._data[CONF_NAME]

def step1_user_init(self, user_input, defaults=None):
def step1_user_init(self, user_input: Dict, defaults=None):
"""Step 1 - general set-up."""
self.errors = {}
if user_input is not None:
Expand Down Expand Up @@ -99,7 +100,7 @@ def step1_user_init(self, user_input, defaults=None):

return False

def step2_annual_group(self, user_input, defaults=None):
def step2_annual_group(self, user_input: Dict, defaults=None):
"""Step 2 - Annual or Group (no week days)."""
self.errors = {}
self.data_schema = {}
Expand Down Expand Up @@ -132,7 +133,7 @@ def step2_annual_group(self, user_input, defaults=None):
)
return False

def step3_detail(self, user_input, defaults=None):
def step3_detail(self, user_input: Dict, defaults=None):
"""Step 2 - other than Annual or Group."""
self.errors = {}
self.data_schema = {}
Expand Down Expand Up @@ -177,7 +178,7 @@ def step3_detail(self, user_input, defaults=None):
] = bool
return False

def step4_final(self, user_input, defaults=None):
def step4_final(self, user_input: Dict, defaults=None):
"""Step 3 - additional parameters."""
self.errors = {}
self.data_schema = {}
Expand Down
18 changes: 10 additions & 8 deletions custom_components/garbage_collection/config_singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ class config_singularity:

options: Dict = {}

def __init__(self):
def __init__(self) -> None:
"""Validate configuration and reset defaults."""
for _, value in self.options.items():
if "method" not in value:
raise ('config_singularity.options must contain the key "method"')
raise KeyError(
'config_singularity.options must contain the key "method"'
)
if "type" not in value:
raise ('config_singularity.options must contain the key "type"')
raise KeyError('config_singularity.options must contain the key "type"')
# Set defaults
self.reset_defaults()

@property
def defaults(self):
def defaults(self) -> Dict:
"""Return default values."""
return self.__defaults

def reset_defaults(self):
def reset_defaults(self) -> None:
"""Reset the defaults from const.py."""
self.__defaults = {}
items = {
Expand All @@ -49,7 +51,7 @@ def reset_defaults(self):
for key, value in items.items():
self.__defaults[key] = value["default"]

def compile_config_flow(self, step, valid_for=None):
def compile_config_flow(self, step: int, valid_for=None) -> Dict:
"""Generate configuration options relevant for current step and frequency."""
result = OrderedDict()
items = {
Expand All @@ -73,7 +75,7 @@ def compile_config_flow(self, step, valid_for=None):
result[value["method"](key)] = value["type"]
return result

def compile_schema(self, step=None, valid_for=None):
def compile_schema(self, step: int = None, valid_for=None) -> Dict:
"""For both YAML Scheme (step is None) or config_flow Scheme."""
result = OrderedDict()
items = {
Expand All @@ -95,7 +97,7 @@ def compile_schema(self, step=None, valid_for=None):
result[value["method"](key)] = t
return result

def set_defaults(self, step, data) -> None:
def set_defaults(self, step: int, data) -> None:
"""Generate default values."""
items = {
key: value
Expand Down
7 changes: 4 additions & 3 deletions custom_components/garbage_collection/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Define constants used in garbage_collection."""

from datetime import datetime
from typing import Any

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -176,7 +177,7 @@
]


def date_text(value):
def date_text(value: Any) -> str:
"""Have to store date as text - datetime is not JSON serialisable."""
if value is None or value == "":
return ""
Expand All @@ -186,7 +187,7 @@ def date_text(value):
raise vol.Invalid(f"Invalid date: {value}")


def time_text(value):
def time_text(value: Any) -> str:
"""Have to store time as text - datetime is not JSON serialisable."""
if value is None or value == "":
return ""
Expand All @@ -196,7 +197,7 @@ def time_text(value):
raise vol.Invalid(f"Invalid date: {value}")


def month_day_text(value):
def month_day_text(value: Any) -> str:
"""Validate format month/day."""
if value is None or value == "":
return ""
Expand Down
5 changes: 1 addition & 4 deletions custom_components/garbage_collection/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
"@bruxy70"
],
"requirements": [
"datetime",
"python-dateutil>=2.8.1",
"holidays>=0.10.1",
"typing",
"uuid",
"voluptuous"
]
}
}
Loading

0 comments on commit e2f106d

Please sign in to comment.