Skip to content

Commit

Permalink
fix new holiday creation from @dcmeglio
Browse files Browse the repository at this point in the history
  • Loading branch information
skweeker committed Jan 4, 2025
1 parent 4e9e391 commit 687a0da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 3 additions & 6 deletions custom_components/calendarific/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

_LOGGER = logging.getLogger(__name__)

holiday_list = []

def setup(hass, config):
"""Set up platform using YAML."""
if DOMAIN in config:
Expand Down Expand Up @@ -95,6 +93,9 @@ def get_description(self,holiday_name):
return next(i for i in self._holidays if i['name'] == holiday_name)['description']
except:
return "NOT FOUND"

def get_holidays(self):
return [item['name'] for item in self._holidays]

def update(self):
if self._lastupdated == datetime.now().date():
Expand All @@ -120,10 +121,6 @@ def update(self):
return
self._error_logged = False
self._next_holidays = response['response']['holidays']
global holiday_list
holiday_list = []
for holiday in self._holidays:
holiday_list.append(holiday['name'])

return True

Expand Down
9 changes: 5 additions & 4 deletions custom_components/calendarific/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import voluptuous as vol

from homeassistant import config_entries
from homeassistant import core
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant, callback

Expand All @@ -27,8 +28,6 @@
CONF_UNIT_OF_MEASUREMENT,
)

from . import holiday_list

_LOGGER = logging.getLogger(__name__)

@callback
Expand All @@ -46,9 +45,11 @@ def __init__(self) -> None:
self._errors = {}
self._data = {}
self._data["unique_id"] = str(uuid.uuid4())
hass = core.async_get_hass()
self._holiday_list = hass.data[DOMAIN]["apiReader"].get_holidays()

async def async_step_user(self, user_input=None):
if holiday_list == []:
if self._holiday_list == []:
return self.async_abort(reason="no_holidays_found")
self._errors = {}
if user_input is not None:
Expand Down Expand Up @@ -84,7 +85,7 @@ async def _show_user_form(self, user_input):
if CONF_UNIT_OF_MEASUREMENT in user_input:
unit_of_measurement = user_input[CONF_UNIT_OF_MEASUREMENT]
data_schema = OrderedDict()
data_schema[vol.Required(CONF_HOLIDAY, default=holiday)] = vol.In(holiday_list)
data_schema[vol.Required(CONF_HOLIDAY, default=holiday)] = vol.In(self._holiday_list)
data_schema[vol.Optional(CONF_NAME, default=name)] = str
data_schema[vol.Required(CONF_UNIT_OF_MEASUREMENT, default=unit_of_measurement)] = str
data_schema[vol.Required(CONF_ICON_NORMAL, default=icon_normal)] = str
Expand Down

0 comments on commit 687a0da

Please sign in to comment.