Skip to content

Commit 3b954fb

Browse files
GitHub ActionsGitHub Actions
authored andcommitted
Run formatting
1 parent c2ba4d5 commit 3b954fb

File tree

6 files changed

+151
-78
lines changed

6 files changed

+151
-78
lines changed

custom_components/isitpayday/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import logging
22
from datetime import date, timedelta
3+
34
from homeassistant.config_entries import ConfigEntry
45
from homeassistant.core import HomeAssistant
5-
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
66
from homeassistant.helpers.typing import ConfigType
7+
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
78

89
from .const import *
910
from .payday_calculator import async_calculate_next_payday
1011

1112
_LOGGER = logging.getLogger(__name__)
1213

14+
1315
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
1416
return True
1517

@@ -35,7 +37,7 @@ async def async_update_data():
3537
data.get(CONF_PAY_DAY),
3638
data.get(CONF_LAST_PAY_DATE),
3739
data.get(CONF_WEEKDAY),
38-
data.get(CONF_BANK_OFFSET, 0)
40+
data.get(CONF_BANK_OFFSET, 0),
3941
)
4042

4143
last_known_payday = new_payday
@@ -54,20 +56,24 @@ async def async_update_data():
5456

5557
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
5658
"coordinator": coordinator,
57-
"name": instance_name
59+
"name": instance_name,
5860
}
5961

6062
await coordinator.async_refresh()
6163

6264
if not coordinator.last_update_success:
6365
_LOGGER.error("Initial data could not be fetched for entry: %s", entry.entry_id)
6466

65-
await hass.config_entries.async_forward_entry_setups(entry, ["sensor", "binary_sensor"])
67+
await hass.config_entries.async_forward_entry_setups(
68+
entry, ["sensor", "binary_sensor"]
69+
)
6670
return True
6771

6872

6973
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
70-
unload_ok = await hass.config_entries.async_unload_platforms(entry, ["sensor", "binary_sensor"])
74+
unload_ok = await hass.config_entries.async_unload_platforms(
75+
entry, ["sensor", "binary_sensor"]
76+
)
7177

7278
if unload_ok:
7379
hass.data[DOMAIN].pop(entry.entry_id, None)

custom_components/isitpayday/binary_sensor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import logging
22
from datetime import date
3+
34
from homeassistant.components.binary_sensor import BinarySensorEntity
4-
from homeassistant.helpers.update_coordinator import CoordinatorEntity, DataUpdateCoordinator
5+
from homeassistant.helpers.update_coordinator import (
6+
CoordinatorEntity,
7+
DataUpdateCoordinator,
8+
)
9+
510
from .const import *
611

712
_LOGGER = logging.getLogger(__name__)
@@ -21,7 +26,9 @@ async def async_setup_entry(hass, entry, async_add_entities):
2126
class IsItPaydaySensor(CoordinatorEntity, BinarySensorEntity):
2227
_attr_device_class = None
2328

24-
def __init__(self, coordinator: DataUpdateCoordinator, entry_id: str, instance_name: str):
29+
def __init__(
30+
self, coordinator: DataUpdateCoordinator, entry_id: str, instance_name: str
31+
):
2532
super().__init__(coordinator)
2633
self._attr_unique_id = f"{entry_id}_is_it_payday"
2734
self._attr_name = f"{instance_name}: Is it payday"

custom_components/isitpayday/config_flow.py

Lines changed: 76 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Config flow for IsItPayday integration."""
22

33
import logging
4+
45
import aiohttp
56
import voluptuous as vol
67
from homeassistant import config_entries
@@ -12,13 +13,7 @@
1213

1314
_LOGGER = logging.getLogger(__name__)
1415

15-
WEEKDAY_MAP = {
16-
"Monday": 0,
17-
"Tuesday": 1,
18-
"Wednesday": 2,
19-
"Thursday": 3,
20-
"Friday": 4
21-
}
16+
WEEKDAY_MAP = {"Monday": 0, "Tuesday": 1, "Wednesday": 2, "Thursday": 3, "Friday": 4}
2217

2318

2419
async def async_get_homeassistant_country(hass: HomeAssistant) -> str | None:
@@ -83,10 +78,11 @@ async def async_step_reconfigure(self, user_input=None):
8378
async def async_step_user(self, user_input=None):
8479
if user_input is None:
8580
self.country_list = await async_fetch_supported_countries()
86-
current_country = self.country or await async_get_homeassistant_country(self.hass) or "DK"
81+
current_country = (
82+
self.country or await async_get_homeassistant_country(self.hass) or "DK"
83+
)
8784
return self.async_show_form(
88-
step_id="user",
89-
data_schema=self._create_user_schema(current_country)
85+
step_id="user", data_schema=self._create_user_schema(current_country)
9086
)
9187

9288
self.name = user_input[CONF_NAME]
@@ -96,8 +92,7 @@ async def async_step_user(self, user_input=None):
9692
async def async_step_frequency(self, user_input=None):
9793
if user_input is None:
9894
return self.async_show_form(
99-
step_id="frequency",
100-
data_schema=self._create_pay_frequency_schema()
95+
step_id="frequency", data_schema=self._create_pay_frequency_schema()
10196
)
10297

10398
self.pay_frequency = user_input[CONF_PAY_FREQ]
@@ -110,7 +105,7 @@ async def async_step_frequency(self, user_input=None):
110105
PAY_FREQ_SEMIANNUAL,
111106
PAY_FREQ_ANNUAL,
112107
PAY_FREQ_28_DAYS,
113-
PAY_FREQ_14_DAYS
108+
PAY_FREQ_14_DAYS,
114109
]:
115110
return await self.async_step_cycle_last_paydate()
116111
elif self.pay_frequency == PAY_FREQ_WEEKLY:
@@ -121,8 +116,7 @@ async def async_step_frequency(self, user_input=None):
121116
async def async_step_monthly_day(self, user_input=None):
122117
if user_input is None:
123118
return self.async_show_form(
124-
step_id="monthly_day",
125-
data_schema=self._create_monthly_day_schema()
119+
step_id="monthly_day", data_schema=self._create_monthly_day_schema()
126120
)
127121

128122
self.pay_day = user_input[CONF_PAY_DAY]
@@ -137,8 +131,7 @@ async def async_step_monthly_day(self, user_input=None):
137131
async def async_step_bank_offset(self, user_input=None):
138132
if user_input is None:
139133
return self.async_show_form(
140-
step_id="bank_offset",
141-
data_schema=self._create_bank_offset_schema()
134+
step_id="bank_offset", data_schema=self._create_bank_offset_schema()
142135
)
143136

144137
self.bank_offset = int(user_input[CONF_BANK_OFFSET])
@@ -147,8 +140,7 @@ async def async_step_bank_offset(self, user_input=None):
147140
async def async_step_specific_day(self, user_input=None):
148141
if user_input is None:
149142
return self.async_show_form(
150-
step_id="specific_day",
151-
data_schema=self._create_specific_day_schema()
143+
step_id="specific_day", data_schema=self._create_specific_day_schema()
152144
)
153145

154146
self.pay_day = int(user_input[CONF_PAY_DAY])
@@ -158,7 +150,7 @@ async def async_step_cycle_last_paydate(self, user_input=None):
158150
if user_input is None:
159151
return self.async_show_form(
160152
step_id="cycle_last_paydate",
161-
data_schema=self._create_last_paydate_schema()
153+
data_schema=self._create_last_paydate_schema(),
162154
)
163155

164156
self.last_pay_date = user_input[CONF_LAST_PAY_DATE]
@@ -167,8 +159,7 @@ async def async_step_cycle_last_paydate(self, user_input=None):
167159
async def async_step_weekly(self, user_input=None):
168160
if user_input is None:
169161
return self.async_show_form(
170-
step_id="weekly",
171-
data_schema=self._create_weekly_schema()
162+
step_id="weekly", data_schema=self._create_weekly_schema()
172163
)
173164

174165
self.pay_day = user_input[CONF_PAY_DAY]
@@ -189,53 +180,85 @@ def _create_entry(self) -> FlowResult:
189180
if self.reconfig_entry:
190181
_LOGGER.info("Updating existing entry: %s", self.reconfig_entry.entry_id)
191182
self.hass.config_entries.async_update_entry(self.reconfig_entry, data=data)
192-
self.hass.async_create_task(self.hass.config_entries.async_reload(self.reconfig_entry.entry_id))
183+
self.hass.async_create_task(
184+
self.hass.config_entries.async_reload(self.reconfig_entry.entry_id)
185+
)
193186

194-
self.hass.async_create_task(self.hass.services.async_call(
195-
"persistent_notification",
196-
"create",
197-
{
198-
"title": "IsItPayday",
199-
"message": f"The configuration for '{self.name}' has been successfully updated."
200-
}
201-
))
187+
self.hass.async_create_task(
188+
self.hass.services.async_call(
189+
"persistent_notification",
190+
"create",
191+
{
192+
"title": "IsItPayday",
193+
"message": f"The configuration for '{self.name}' has been successfully updated.",
194+
},
195+
)
196+
)
202197

203198
return self.async_abort(reason="reconfigured")
204199

205200
return self.async_create_entry(title=self.name, data=data)
206201

207202
def _create_user_schema(self, default_country: str) -> vol.Schema:
208-
return vol.Schema({
209-
vol.Required(CONF_NAME, default=self.name or ""): str,
210-
vol.Required(CONF_COUNTRY, default=default_country): vol.In(self.country_list)
211-
})
203+
return vol.Schema(
204+
{
205+
vol.Required(CONF_NAME, default=self.name or ""): str,
206+
vol.Required(CONF_COUNTRY, default=default_country): vol.In(
207+
self.country_list
208+
),
209+
}
210+
)
212211

213212
def _create_pay_frequency_schema(self) -> vol.Schema:
214-
return vol.Schema({
215-
vol.Required(CONF_PAY_FREQ, default=self.pay_frequency or PAY_FREQ_MONTHLY): vol.In(PAY_FREQ_OPTIONS)
216-
})
213+
return vol.Schema(
214+
{
215+
vol.Required(
216+
CONF_PAY_FREQ, default=self.pay_frequency or PAY_FREQ_MONTHLY
217+
): vol.In(PAY_FREQ_OPTIONS)
218+
}
219+
)
217220

218221
def _create_monthly_day_schema(self) -> vol.Schema:
219-
return vol.Schema({
220-
vol.Required(CONF_PAY_DAY, default=self.pay_day or PAY_DAY_LAST_BANK_DAY): vol.In(PAY_MONTHLY_OPTIONS)
221-
})
222+
return vol.Schema(
223+
{
224+
vol.Required(
225+
CONF_PAY_DAY, default=self.pay_day or PAY_DAY_LAST_BANK_DAY
226+
): vol.In(PAY_MONTHLY_OPTIONS)
227+
}
228+
)
222229

223230
def _create_bank_offset_schema(self) -> vol.Schema:
224-
return vol.Schema({
225-
vol.Required(CONF_BANK_OFFSET, default=self.bank_offset or 0): vol.In(range(0, 11))
226-
})
231+
return vol.Schema(
232+
{
233+
vol.Required(CONF_BANK_OFFSET, default=self.bank_offset or 0): vol.In(
234+
range(0, 11)
235+
)
236+
}
237+
)
227238

228239
def _create_specific_day_schema(self) -> vol.Schema:
229-
return vol.Schema({
230-
vol.Required(CONF_PAY_DAY, default=self.pay_day or 31): vol.In(range(1, 32))
231-
})
240+
return vol.Schema(
241+
{
242+
vol.Required(CONF_PAY_DAY, default=self.pay_day or 31): vol.In(
243+
range(1, 32)
244+
)
245+
}
246+
)
232247

233248
def _create_last_paydate_schema(self) -> vol.Schema:
234-
return vol.Schema({
235-
vol.Required(CONF_LAST_PAY_DATE, default=self.last_pay_date): DateSelector()
236-
})
249+
return vol.Schema(
250+
{
251+
vol.Required(
252+
CONF_LAST_PAY_DATE, default=self.last_pay_date
253+
): DateSelector()
254+
}
255+
)
237256

238257
def _create_weekly_schema(self) -> vol.Schema:
239-
return vol.Schema({
240-
vol.Required(CONF_PAY_DAY, default=self.pay_day or "Monday"): vol.In(WEEKDAY_OPTIONS)
241-
})
258+
return vol.Schema(
259+
{
260+
vol.Required(CONF_PAY_DAY, default=self.pay_day or "Monday"): vol.In(
261+
WEEKDAY_OPTIONS
262+
)
263+
}
264+
)

custom_components/isitpayday/const.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
PAY_MONTHLY_OPTIONS = {
5454
PAY_DAY_LAST_BANK_DAY: "Last bank day",
5555
PAY_DAY_FIRST_BANK_DAY: "First bank day",
56-
PAY_DAY_SPECIFIC_DAY: "Specific day"
56+
PAY_DAY_SPECIFIC_DAY: "Specific day",
5757
}
5858

5959
DAYS_BEFORE_OPTIONS = [str(i) for i in range(0, 11)] # 0 til 10 som tekst
@@ -118,4 +118,6 @@
118118

119119
# Validation errors
120120
ERROR_WEEKDAY_REQUIRED_FOR_WEEKLY = "Weekly frequency requires weekday to be set."
121-
ERROR_LAST_PAYDATE_REQUIRED = "Last payday date is required for 14-day or 28-day pay frequencies."
121+
ERROR_LAST_PAYDATE_REQUIRED = (
122+
"Last payday date is required for 14-day or 28-day pay frequencies."
123+
)

0 commit comments

Comments
 (0)