Skip to content

Commit

Permalink
HACS update - calendarific - #16
Browse files Browse the repository at this point in the history
  • Loading branch information
BeardedTinker committed Sep 5, 2020
1 parent a1e1687 commit 884741f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
6 changes: 6 additions & 0 deletions custom_components/calendarific/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
DEFAULT_ICON_TODAY,
DEFAULT_DATE_FORMAT,
DEFAULT_SOON,
DEFAULT_UNIT_OF_MEASUREMENT,
CONF_ICON_NORMAL,
CONF_ICON_TODAY,
CONF_ICON_SOON,
CONF_HOLIDAY,
CONF_DATE_FORMAT,
CONF_SOON,
CONF_UNIT_OF_MEASUREMENT,
)

from . import holiday_list
Expand Down Expand Up @@ -65,6 +67,7 @@ async def _show_user_form(self, user_input):
icon_today = DEFAULT_ICON_TODAY
date_format = DEFAULT_DATE_FORMAT
days_as_soon = DEFAULT_SOON
unit_of_measurement = DEFAULT_UNIT_OF_MEASUREMENT
if user_input is not None:
if CONF_NAME in user_input:
name = user_input[CONF_NAME]
Expand All @@ -78,9 +81,12 @@ async def _show_user_form(self, user_input):
icon_today = user_input[CONF_ICON_TODAY]
if CONF_DATE_FORMAT in user_input:
date_format = user_input[CONF_DATE_FORMAT]
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.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
data_schema[vol.Required(CONF_ICON_TODAY, default=icon_today)] = str
data_schema[vol.Required(CONF_SOON, default=days_as_soon)] = int
Expand Down
6 changes: 4 additions & 2 deletions custom_components/calendarific/const.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""" Constants """
# Base component constants
DOMAIN = "calendarific"
VERSION = "0.10.3"
VERSION = "0.11.0"
ISSUE_URL = "https://github.com/pinkywafer/Calendarific/issues"
ATTRIBUTION = "Data from this is provided by calendarific.com"
ATTRIBUTION = "Data provided by calendarific.com"

ATTR_DATE = "date"

Expand All @@ -15,13 +15,15 @@
CONF_DATE_FORMAT = "date_format"
CONF_SOON = "days_as_soon"
CONF_HOLIDAY = "holiday"
CONF_UNIT_OF_MEASUREMENT = "unit_of_measurement"

# Defaults
DEFAULT_ICON_NORMAL = "mdi:calendar-blank"
DEFAULT_ICON_TODAY = "mdi:calendar-star"
DEFAULT_ICON_SOON = "mdi:calendar"
DEFAULT_DATE_FORMAT = "%Y-%m-%d"
DEFAULT_SOON = 1
DEFAULT_UNIT_OF_MEASUREMENT = "Days"



20 changes: 13 additions & 7 deletions custom_components/calendarific/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from homeassistant.components.sensor import PLATFORM_SCHEMA

from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_NAME, ATTR_ATTRIBUTION
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity

Expand All @@ -17,12 +17,14 @@
DEFAULT_ICON_NORMAL,
DEFAULT_ICON_TODAY,
DEFAULT_DATE_FORMAT,
DEFAULT_UNIT_OF_MEASUREMENT,
CONF_ICON_NORMAL,
CONF_ICON_TODAY,
CONF_ICON_SOON,
CONF_DATE_FORMAT,
CONF_SOON,
CONF_HOLIDAY,
CONF_UNIT_OF_MEASUREMENT,
DOMAIN,
)

Expand All @@ -38,6 +40,7 @@
vol.Optional(CONF_ICON_TODAY, default=DEFAULT_ICON_TODAY): cv.icon,
vol.Optional(CONF_ICON_SOON, default=DEFAULT_ICON_SOON): cv.icon,
vol.Optional(CONF_DATE_FORMAT, default=DEFAULT_DATE_FORMAT): cv.string,
vol.Optional(CONF_UNIT_OF_MEASUREMENT, default=DEFAULT_UNIT_OF_MEASUREMENT): cv.string,
}
)

Expand Down Expand Up @@ -70,6 +73,9 @@ def __init__(self, config, reader):
self._icon_soon = config.get(CONF_ICON_SOON)
self._soon = config.get(CONF_SOON)
self._date_format = config.get(CONF_DATE_FORMAT)
self._unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
if self._unit_of_measurement is None:
self._unit_of_measurement = DEFAULT_UNIT_OF_MEASUREMENT
self._icon = self._icon_normal
self._reader = reader
self._description = self._reader.get_description(self._holiday)
Expand Down Expand Up @@ -98,16 +104,16 @@ def state(self):
@property
def device_state_attributes(self):
"""Return the state attributes."""
res = {}
res[ATTR_DATE] = self._attr_date
res[ATTR_DESCRIPTION] = self._description
return res
return {
ATTR_DATE: self._attr_date,
ATTR_DESCRIPTION: self._description,
ATTR_ATTRIBUTION: ATTRIBUTION,
}

@property
def unit_of_measurement(self):
"""Return the unit this state is expressed in."""
if self._date != "-":
return "days"
return self._unit_of_measurement

@property
def icon(self):
Expand Down

0 comments on commit 884741f

Please sign in to comment.