From 884741fb580bf3cbf6a011253827f72ca99725e9 Mon Sep 17 00:00:00 2001 From: BeardedTinker Date: Sat, 5 Sep 2020 17:03:48 +0200 Subject: [PATCH] HACS update - calendarific - #16 --- custom_components/calendarific/config_flow.py | 6 ++++++ custom_components/calendarific/const.py | 6 ++++-- custom_components/calendarific/sensor.py | 20 ++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/custom_components/calendarific/config_flow.py b/custom_components/calendarific/config_flow.py index 27d5a606..b111ea2b 100644 --- a/custom_components/calendarific/config_flow.py +++ b/custom_components/calendarific/config_flow.py @@ -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 @@ -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] @@ -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 diff --git a/custom_components/calendarific/const.py b/custom_components/calendarific/const.py index f9882b77..f6935e70 100644 --- a/custom_components/calendarific/const.py +++ b/custom_components/calendarific/const.py @@ -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" @@ -15,6 +15,7 @@ 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" @@ -22,6 +23,7 @@ DEFAULT_ICON_SOON = "mdi:calendar" DEFAULT_DATE_FORMAT = "%Y-%m-%d" DEFAULT_SOON = 1 +DEFAULT_UNIT_OF_MEASUREMENT = "Days" diff --git a/custom_components/calendarific/sensor.py b/custom_components/calendarific/sensor.py index cf9daa17..080e0306 100644 --- a/custom_components/calendarific/sensor.py +++ b/custom_components/calendarific/sensor.py @@ -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 @@ -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, ) @@ -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, } ) @@ -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) @@ -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):