Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring in changes #4

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions custom_components/calendarific/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

from homeassistant import config_entries
Expand Down Expand Up @@ -37,8 +38,6 @@

_LOGGER = logging.getLogger(__name__)

holiday_list = []

def setup(hass, config):
"""Set up platform using YAML."""
if DOMAIN in config:
Expand All @@ -54,14 +53,12 @@ def setup(hass, config):


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
await hass.config_entries.async_forward_entry_setups(entry, [Platform.SENSOR])
return True

async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.config_entries.async_forward_entry_unload(entry, "sensor")
return await hass.config_entries.async_forward_entry_unload(entry, Platform.SENSOR)

class CalendarificApiReader:

Expand Down Expand Up @@ -96,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 @@ -121,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