Skip to content

Commit 6e49a20

Browse files
committed
Code formatting
1 parent 7c74128 commit 6e49a20

File tree

7 files changed

+38
-33
lines changed

7 files changed

+38
-33
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Constants for eskom loadshedding interface"""
2+
23
# Base component constants
34
NAME = "Eskom Loadshedding Interface"
45
DEVICE_NAME = "Loadshedding"

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,

custom_components/eskom_loadshedding/sensor.py

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

56
from homeassistant.components.sensor import SensorEntity
67

@@ -156,10 +157,8 @@ def native_value(self):
156157
matches = re.findall(r"\d+", events[0]["note"])
157158
if matches:
158159
return int(matches[0])
159-
else:
160-
return events[0]["note"]
161-
else:
162-
return 0
160+
return events[0]["note"]
161+
return 0
163162

164163
@property
165164
def icon(self):
@@ -219,6 +218,8 @@ def native_value(self):
219218
if allowance:
220219
return int(allowance["limit"]) - int(allowance["count"])
221220

221+
return None
222+
222223
@property
223224
def icon(self):
224225
"""Return the icon of the sensor."""
@@ -236,3 +237,4 @@ def extra_state_attributes(self):
236237
"Limit": int(allowance["limit"]),
237238
"Type": allowance["type"],
238239
}
240+
return None

0 commit comments

Comments
 (0)