Skip to content

Commit 5a653a5

Browse files
authored
Merge pull request #45 from swartjean/v1.1.3
V1.1.3
2 parents 8e2cc2d + da78a9e commit 5a653a5

File tree

19 files changed

+183
-98
lines changed

19 files changed

+183
-98
lines changed

.devcontainer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "ludeeus/integration_blueprint",
3+
"image": "mcr.microsoft.com/devcontainers/python:3.12",
4+
"postCreateCommand": "scripts/setup",
5+
"forwardPorts": [
6+
8123
7+
],
8+
"portsAttributes": {
9+
"8123": {
10+
"label": "Home Assistant",
11+
"onAutoForward": "notify"
12+
}
13+
},
14+
"customizations": {
15+
"vscode": {
16+
"extensions": [
17+
"charliermarsh.ruff",
18+
"github.vscode-pull-request-github",
19+
"ms-python.python",
20+
"ms-python.vscode-pylance",
21+
"ryanluker.vscode-coverage-gutters"
22+
],
23+
"settings": {
24+
"files.eol": "\n",
25+
"editor.tabSize": 4,
26+
"editor.formatOnPaste": true,
27+
"editor.formatOnSave": true,
28+
"editor.formatOnType": false,
29+
"files.trimTrailingWhitespace": true,
30+
"python.analysis.typeCheckingMode": "basic",
31+
"python.analysis.autoImportCompletions": true,
32+
"python.defaultInterpreterPath": "/usr/local/bin/python",
33+
"[python]": {
34+
"editor.defaultFormatter": "charliermarsh.ruff"
35+
}
36+
}
37+
}
38+
},
39+
"remoteUser": "vscode",
40+
"features": {}
41+
}

.devcontainer/configuration.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

.gitignore

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
__pycache__
1+
# artifacts
2+
__pycache__
3+
.pytest*
4+
*.egg-info
5+
*/build/*
6+
*/dist/*
7+
8+
9+
# misc
10+
.coverage
11+
.vscode
12+
coverage.xml
13+
.ruff_cache
14+
15+
16+
# Home Assistant configuration
17+
config/*
18+
!config/configuration.yaml

.ruff.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml
2+
3+
target-version = "py312"
4+
5+
[lint]
6+
select = [
7+
"ALL",
8+
]
9+
10+
ignore = [
11+
"ANN101", # Missing type annotation for `self` in method
12+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
13+
"D203", # no-blank-line-before-class (incompatible with formatter)
14+
"D212", # multi-line-summary-first-line (incompatible with formatter)
15+
"COM812", # incompatible with formatter
16+
"ISC001", # incompatible with formatter
17+
]
18+
19+
[lint.flake8-pytest-style]
20+
fixture-parentheses = false
21+
22+
[lint.pyupgrade]
23+
keep-runtime-typing = true
24+
25+
[lint.mccabe]
26+
max-complexity = 25

.vscode/tasks.json

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,9 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"label": "Run Home Assistant on port 9123",
5+
"label": "Run Home Assistant on port 8123",
66
"type": "shell",
7-
"command": "container start",
8-
"problemMatcher": []
9-
},
10-
{
11-
"label": "Run Home Assistant configuration against /config",
12-
"type": "shell",
13-
"command": "container check",
14-
"problemMatcher": []
15-
},
16-
{
17-
"label": "Upgrade Home Assistant to latest dev",
18-
"type": "shell",
19-
"command": "container install",
20-
"problemMatcher": []
21-
},
22-
{
23-
"label": "Install a spesific version of Home Assistant",
24-
"type": "shell",
25-
"command": "container set-version",
7+
"command": "scripts/develop",
268
"problemMatcher": []
279
}
2810
]

config/configuration.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# https://www.home-assistant.io/integrations/default_config/
2+
default_config:
3+
4+
# https://www.home-assistant.io/integrations/homeassistant/
5+
homeassistant:
6+
debug: true
7+
8+
# https://www.home-assistant.io/integrations/logger/
9+
logger:
10+
default: info
11+
logs:
12+
custom_components.integration_blueprint: debug

custom_components/eskom_loadshedding/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
For more details about this integration, please refer to
55
https://github.com/swartjean/ha-eskom-loadshedding
66
"""
7+
78
import asyncio
8-
from datetime import timedelta
99
import logging
10+
from datetime import timedelta
1011

1112
from homeassistant.config_entries import ConfigEntry
1213
from homeassistant.core import HomeAssistant
@@ -16,8 +17,8 @@
1617
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
1718

1819
from .const import (
19-
CONF_SCAN_PERIOD,
2020
CONF_API_KEY,
21+
CONF_SCAN_PERIOD,
2122
DEFAULT_SCAN_PERIOD,
2223
DOMAIN,
2324
PLATFORMS,
@@ -57,7 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
5758

5859
hass.data[DOMAIN][entry.entry_id] = coordinator
5960

60-
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
61+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
6162

6263
if not entry.update_listeners:
6364
entry.add_update_listener(async_reload_entry)

custom_components/eskom_loadshedding/calendar.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
"""Sensor platform for Eskom Loadshedding Interface."""
2-
from datetime import datetime, timedelta
2+
33
import re
4+
from datetime import datetime, timedelta
45

56
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
67
from homeassistant.core import callback
78

89
from .const import (
10+
DEFAULT_CALENDAR_SCAN_PERIOD,
911
DOMAIN,
1012
LOCAL_EVENTS_ID,
1113
LOCAL_EVENTS_NAME,
1214
LOCAL_SCHEDULE_ID,
1315
LOCAL_SCHEDULE_NAME,
14-
DEFAULT_CALENDAR_SCAN_PERIOD,
1516
)
1617
from .entity import EskomEntity
1718

@@ -62,7 +63,8 @@ def name(self):
6263

6364
@property
6465
def should_poll(self) -> bool:
65-
"""Enable polling for the entity.
66+
"""
67+
Enable polling for the entity.
6668
6769
The coordinator is used to query the API, but polling is used to update
6870
the entity state more frequently.
@@ -112,11 +114,11 @@ async def async_get_events(
112114
)
113115
for event in events
114116
]
115-
else:
116-
return []
117+
return []
117118

118119
async def async_update(self) -> None:
119-
"""Disable update behavior.
120+
"""
121+
Disable update behavior.
120122
Event updates are performed through the coordinator callback.
121123
This is simply used to evaluate the entity state
122124
"""
@@ -145,7 +147,8 @@ def name(self):
145147

146148
@property
147149
def should_poll(self) -> bool:
148-
"""Enable polling for the entity.
150+
"""
151+
Enable polling for the entity.
149152
150153
The coordinator is used to query the API, but polling is used to update
151154
the entity state more frequently.
@@ -215,11 +218,11 @@ async def async_get_events(
215218
)
216219

217220
return calendar_events
218-
else:
219-
return []
221+
return []
220222

221223
async def async_update(self) -> None:
222-
"""Disable update behavior.
224+
"""
225+
Disable update behavior.
223226
Event updates are performed through the coordinator callback.
224227
This is simply used to evaluate the entity state
225228
"""

custom_components/eskom_loadshedding/config_flow.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"""Adds config flow for the Eskom Loadshedding Interface."""
2+
23
from collections import OrderedDict
34

5+
import voluptuous as vol
46
from homeassistant import config_entries
57
from homeassistant.core import callback
68
from homeassistant.helpers.aiohttp_client import async_create_clientsession
79
from homeassistant.helpers.selector import selector
8-
import voluptuous as vol
910

1011
from .const import ( # pylint: disable=unused-import
11-
CONF_SCAN_PERIOD,
1212
CONF_API_KEY,
13+
CONF_SCAN_PERIOD,
1314
DEFAULT_SCAN_PERIOD,
1415
DOMAIN,
1516
MIN_SCAN_PERIOD,
@@ -41,8 +42,7 @@ async def async_step_user(self, user_input=None):
4142
# Proceed to the next configuration step
4243
return await self.async_step_area_search()
4344

44-
else:
45-
self._errors["base"] = "auth"
45+
self._errors["base"] = "auth"
4646

4747
return await self._show_user_config_form(user_input)
4848

@@ -91,8 +91,7 @@ async def async_step_area_selection(self, user_input=None):
9191
CONF_API_KEY: self.api_key,
9292
},
9393
)
94-
else:
95-
self._errors["base"] = "no_area_selection"
94+
self._errors["base"] = "no_area_selection"
9695

9796
# Reformat the areas as label/value pairs for the selector
9897
area_options = [
@@ -146,8 +145,7 @@ async def validate_key(self, api_key: str) -> bool:
146145
data = await interface.async_query_api("/api_allowance")
147146
if "error" in data:
148147
return False
149-
else:
150-
return True
148+
return True
151149
except Exception: # pylint: disable=broad-except
152150
pass
153151
return False
@@ -187,8 +185,7 @@ async def async_step_user(self, user_input=None):
187185
# Update all options
188186
self.options.update(user_input)
189187
return await self._update_options()
190-
else:
191-
self._errors["base"] = "auth"
188+
self._errors["base"] = "auth"
192189

193190
data_schema = OrderedDict()
194191
data_schema[
@@ -226,8 +223,7 @@ async def validate_key(self, api_key: str) -> bool:
226223

227224
if "error" in data:
228225
return False
229-
else:
230-
return True
226+
return True
231227
except Exception: # pylint: disable=broad-except
232228
pass
233229
return False

custom_components/eskom_loadshedding/const.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Constants for eskom loadshedding interface"""
2+
23
# Base component constants
34
NAME = "Eskom Loadshedding Interface"
45
DEVICE_NAME = "Loadshedding"
56
DOMAIN = "eskom_loadshedding"
67
DOMAIN_DATA = f"{DOMAIN}_data"
7-
VERSION = "1.1.2"
8+
VERSION = "1.1.3"
89

910
ISSUE_URL = "https://github.com/swartjean/ha-eskom-loadshedding/issues"
1011

custom_components/eskom_loadshedding/entity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""EskomEntity class"""
2+
23
from homeassistant.helpers.update_coordinator import CoordinatorEntity
34

45
from .const import DEVICE_NAME, DOMAIN, VERSION

custom_components/eskom_loadshedding/eskom_interface.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import logging
32
import socket
43

@@ -25,14 +24,16 @@ def __init__(
2524
}
2625

2726
async def async_query_api(self, endpoint: str, payload: dict = None):
28-
"""Queries a given endpoint on the EskomSePush API with the specified payload
27+
"""
28+
Queries a given endpoint on the EskomSePush API with the specified payload
2929
3030
Args:
3131
endpoint (string): The endpoint of the EskomSePush API
3232
payload (dict, optional): The parameters to apply to the query. Defaults to None.
3333
3434
Returns:
3535
The response object from the request
36+
3637
"""
3738
query_url = self.base_url + endpoint
3839
try:
@@ -52,7 +53,7 @@ async def async_query_api(self, endpoint: str, payload: dict = None):
5253
# Re-raise the ClientResponseError to allow checking for valid headers during config
5354
# These will be caught by the DataUpdateCoordinator
5455
raise
55-
except asyncio.TimeoutError as exception:
56+
except TimeoutError as exception:
5657
_LOGGER.error(
5758
"Timeout fetching information from %s: %s",
5859
query_url,

0 commit comments

Comments
 (0)