Skip to content

Commit

Permalink
🔧 big update
Browse files Browse the repository at this point in the history
  • Loading branch information
kernehed committed Apr 23, 2020
1 parent d43492c commit 5cbe664
Show file tree
Hide file tree
Showing 102 changed files with 463 additions and 189 deletions.
10 changes: 10 additions & 0 deletions automations/other/update_plant_problems.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
alias: 'Update Plant Problems'
trigger:
- platform: state
entity_id:
- plant.flower_1
- plant.flower_2
- plant.flower_3
- plant.flower_4
action:
- service: python_script.plant_problems
10 changes: 10 additions & 0 deletions automations/system/startup_automation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
alias: 'Set startup theme'
initial_state: 'on'
trigger:
- platform: homeassistant
event: start
action:
- service: frontend.set_theme
data:
name: darkydark
- service: python_script.plant_problems
9 changes: 0 additions & 9 deletions automations/system/startup_theme.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion automations/tts/guest_mode_tts.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
alias: Guest Mode TTS Feed back
initial_state: 'on'
id: '1545925758712312300'
id: '1545925758712321312123123312123300'
trigger:
platform: state
entity_id: input_boolean.guest_mode
Expand Down
2 changes: 1 addition & 1 deletion automations/tts/idesprutan.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
alias: 'skarmtid'
alias: 'idesprutan'

trigger:
- platform: state
Expand Down
11 changes: 11 additions & 0 deletions automations/tts/plantorna.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
alias: 'plantorna'

trigger:
- platform: state
entity_id: input_boolean.plantorna
to: 'on'

action:
- service: script.speech_engine
data:
call_plants: 1
3 changes: 2 additions & 1 deletion automations/tts/welcome_home.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ action:
{{greeting_sentence(person)}}
call_responsibilities: 1
call_inspirational_quote: 1
call_evenice_skola: 1
call_evenice_skola: 1
call_arsdag: 1
3 changes: 3 additions & 0 deletions components/input_booleans/plantorna.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plantorna:
name: Plantorna
initial: off
6 changes: 0 additions & 6 deletions components/packages/pi_hole.yaml

This file was deleted.

1 change: 1 addition & 0 deletions components/packages/python_script.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_script:
3 changes: 2 additions & 1 deletion components/plants/flower_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ citronfikus:
moisture: sensor.flower_1_moisture
temperature: sensor.flower_1_temperature
conductivity: sensor.flower_1_conductivity
brightness: sensor.flower_1_illuminance
brightness: sensor.flower_1_illuminance
min_conductivity: 200
3 changes: 2 additions & 1 deletion components/plants/flower_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ aloevera_theus:
moisture: sensor.flower_2_moisture
temperature: sensor.flower_2_temperature
conductivity: sensor.flower_2_conductivity
brightness: sensor.flower_2_illuminance
brightness: sensor.flower_2_illuminance
min_conductivity: 200
3 changes: 2 additions & 1 deletion components/plants/flower_3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ aloevera_evenice:
moisture: sensor.flower_3_moisture
temperature: sensor.flower_3_temperature
conductivity: sensor.flower_3_conductivity
brightness: sensor.flower_3_illuminance
brightness: sensor.flower_3_illuminance
min_conductivity: 200
3 changes: 2 additions & 1 deletion components/plants/flower_4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dionaea_theus:
moisture: sensor.flower_4_moisture
temperature: sensor.flower_4_temperature
conductivity: sensor.flower_4_conductivity
brightness: sensor.flower_4_illuminance
brightness: sensor.flower_4_illuminance
min_conductivity: 200
11 changes: 0 additions & 11 deletions components/sensors/miflora_flower_1.yaml

This file was deleted.

12 changes: 6 additions & 6 deletions components/sensors/rest/days_until_easter.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
platform: rest
name: Easter Countdown
resource: !secret wolfram_alpha_easter_api
value_template: "{{ (value|replace(' days', '')) | int }}"
unit_of_measurement: Days
scan_interval: 43200
#platform: rest
#name: Easter Countdown
#resource: !secret wolfram_alpha_easter_api
#value_template: "{{ (value|replace(' days', '')) | int }}"
#unit_of_measurement: Days
#scan_interval: 43200
Binary file not shown.
Binary file not shown.
Binary file modified custom_components/anniversaries/__pycache__/const.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/anniversaries/__pycache__/sensor.cpython-37.pyc
Binary file not shown.
12 changes: 10 additions & 2 deletions custom_components/anniversaries/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DEFAULT_ICON_TODAY,
DEFAULT_DATE_FORMAT,
DEFAULT_SOON,
DEFAULT_HALF_ANNIVERSARY,
CONF_SENSOR,
CONF_ENABLED,
CONF_ICON_NORMAL,
Expand All @@ -24,6 +25,7 @@
CONF_DATE_FORMAT,
CONF_SENSORS,
CONF_SOON,
CONF_HALF_ANNIVERSARY,
)

from homeassistant.const import CONF_NAME
Expand Down Expand Up @@ -58,6 +60,7 @@ async def _show_user_form(self, user_input):
icon_today = DEFAULT_ICON_TODAY
date_format = DEFAULT_DATE_FORMAT
days_as_soon = DEFAULT_SOON
half_anniversary= DEFAULT_HALF_ANNIVERSARY
if user_input is not None:
if CONF_NAME in user_input:
name = user_input[CONF_NAME]
Expand All @@ -71,6 +74,8 @@ 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_HALF_ANNIVERSARY in user_input:
half_anniversary = user_input[CONF_HALF_ANNIVERSARY]
data_schema = OrderedDict()
data_schema[vol.Required(CONF_NAME, default=name)] = str
data_schema[vol.Required(CONF_DATE, default=date)] = str
Expand All @@ -79,6 +84,7 @@ async def _show_user_form(self, user_input):
data_schema[vol.Required(CONF_SOON, default=days_as_soon)] = int
data_schema[vol.Required(CONF_ICON_SOON, default=icon_soon)] = str
data_schema[vol.Required(CONF_DATE_FORMAT, default=date_format)] = str
data_schema[vol.Required(CONF_HALF_ANNIVERSARY, default=half_anniversary)] = bool
return self.async_show_form(step_id="user", data_schema=vol.Schema(data_schema), errors=self._errors)

async def async_step_import(self, user_input): # pylint: disable=unused-argument
Expand Down Expand Up @@ -114,7 +120,8 @@ def is_not_date(date):
class OptionsFlowHandler(config_entries.OptionsFlow):
def __init__(self, config_entry):
self.config_entry = config_entry
self._data = config_entry.options
self._data = {}
self._data["unique_id"] = config_entry.options.get("unique_id")

async def async_step_init(self, user_input=None):
self._errors = {}
Expand All @@ -130,10 +137,11 @@ async def _show_init_form(self, user_input):
data_schema = OrderedDict()
data_schema[vol.Required(CONF_DATE, default=self.config_entry.options.get(CONF_DATE),)] = str
data_schema[vol.Required(CONF_ICON_NORMAL,default=self.config_entry.options.get(CONF_ICON_NORMAL),)] = str
data_schema[vol.Required(CONF_ICON_TODAY,default=self.config_entry.options.get(CONF_ICON_SOON),)] = str
data_schema[vol.Required(CONF_ICON_TODAY,default=self.config_entry.options.get(CONF_ICON_TODAY),)] = str
data_schema[vol.Required(CONF_SOON,default=self.config_entry.options.get(CONF_SOON),)] = int
data_schema[vol.Required(CONF_ICON_SOON,default=self.config_entry.options.get(CONF_ICON_SOON),)] = str
data_schema[vol.Required(CONF_DATE_FORMAT,default=self.config_entry.options.get(CONF_DATE_FORMAT),)] = str
data_schema[vol.Required(CONF_HALF_ANNIVERSARY,default=self.config_entry.options.get(CONF_HALF_ANNIVERSARY),)] = bool
return self.async_show_form(
step_id="init", data_schema=vol.Schema(data_schema), errors=self._errors
)
Expand Down
10 changes: 6 additions & 4 deletions custom_components/anniversaries/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Base component constants
DOMAIN = "anniversaries"
DOMAIN_DATA = f"{DOMAIN}_data"
VERSION = "1.8.0"
VERSION = "2.0.3"
PLATFORM = "sensor"
ISSUE_URL = "https://github.com/pinkywafer/Anniversaries/issues"
ATTRIBUTION = "Data from this is provided by Anniversaries"
Expand All @@ -30,17 +30,18 @@
CONF_DATE_FORMAT = "date_format"
CONF_SENSORS = "sensors"
CONF_SOON = "days_as_soon"
CONF_HALF_ANNIVERSARY = "show_half_anniversary"

# Defaults
DEFAULT_NAME = DOMAIN

# Icons
DEFAULT_ICON_NORMAL = "mdi:calendar-blank"
DEFAULT_ICON_TODAY = "mdi:calendar-star"
DEFAULT_ICON_SOON = "mdi:calendar"
DEFAULT_DATE_FORMAT = "%Y-%m-%d"
ICON = DEFAULT_ICON_NORMAL
DEFAULT_SOON = 1
DEFAULT_HALF_ANNIVERSARY = False

ICON = DEFAULT_ICON_NORMAL

def check_date(value):
try:
Expand All @@ -62,6 +63,7 @@ def check_date(value):
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_HALF_ANNIVERSARY, default=DEFAULT_HALF_ANNIVERSARY): cv.boolean,
}
)

Expand Down
7 changes: 5 additions & 2 deletions custom_components/anniversaries/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"config_flow": true,
"codeowners": ["@pinkywafer"],
"requirements": [
"sampleclient",
"integrationhelper"
"datetime",
"python-dateutil",
"integrationhelper",
"uuid",
"voluptuous"
],
"homeassistant": "0.96.0"
}
57 changes: 39 additions & 18 deletions custom_components/anniversaries/sensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
""" sensor """

from homeassistant.helpers.entity import Entity
import logging
from dateutil.relativedelta import relativedelta
from datetime import datetime, date, timedelta

import logging
from homeassistant.helpers.entity import Entity
from homeassistant.core import HomeAssistant, State

from homeassistant.const import (
Expand All @@ -21,12 +23,15 @@
CONF_DATE,
CONF_DATE_FORMAT,
CONF_SOON,
CONF_HALF_ANNIVERSARY,
)

ATTR_YEARS_NEXT = "years_at_next_anniversary"
ATTR_YEARS_CURRENT = "current_years"
ATTR_DATE = "date"
ATTR_WEEKS = "weeks_remaining"
ATTR_HALF_DATE = "half_anniversary_date"
ATTR_HALF_DAYS = "days_until_half_anniversary"

async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Setup the sensor platform."""
Expand All @@ -47,7 +52,7 @@ def __init__(self, hass, config):
try:
self._date = datetime.strptime(config.get(CONF_DATE), "%Y-%m-%d")
except:
self._date = datetime.strptime(str(date.today().year) + "-" + config.get(CONF_DATE), "%Y-%m-%d")
self._date = datetime.strptime("2020-" + config.get(CONF_DATE), "%Y-%m-%d")
self._unknown_year = True
self._icon_normal = config.get(CONF_ICON_NORMAL)
self._icon_today = config.get(CONF_ICON_TODAY)
Expand All @@ -59,6 +64,10 @@ def __init__(self, hass, config):
self._years_current = 0
self._state = 0
self._weeks_remaining = 0
self._show_half_anniversary = config.get(CONF_HALF_ANNIVERSARY)
if self._show_half_anniversary:
self._half_days_remaining = 0
self._half_date = self._date + relativedelta(months=+6)

@property
def unique_id(self):
Expand All @@ -84,6 +93,9 @@ def device_state_attributes(self):
res[ATTR_YEARS_CURRENT] = self._years_current
res[ATTR_DATE] = datetime.strftime(self._date,self._date_format)
res[ATTR_WEEKS] = self._weeks_remaining
if self._show_half_anniversary:
res[ATTR_HALF_DATE] = datetime.strftime(self._half_date, self._date_format)
res[ATTR_HALF_DAYS] = self._half_days_remaining
return res

@property
Expand All @@ -100,30 +112,39 @@ def unit_of_measurement(self):
async def async_update(self):
"""update the sensor"""
today = date.today()
nextDate = date(today.year, self._date.month, self._date.day)
if today < self._date.date():
nextDate = self._date.date()
daysRemaining = 0
years = today.year - self._date.year
if today < nextDate:
daysRemaining = (nextDate - today).days
elif today == nextDate:
daysRemaining = 0
years = years + 1
elif today > nextDate:
nextDate = date(today.year + 1, self._date.month, self._date.day)
daysRemaining = (nextDate - today).days
years = years + 1
if self._unknown_year:
self._date = datetime(nextDate.year, nextDate.month, nextDate.day)
nextDate = self._date.date()

if today >= nextDate:
nextDate = self._date.date() + relativedelta(year=today.year)
if today == nextDate:
years = years + 1
if today > nextDate:
nextDate = self._date.date() + relativedelta(year=today.year + 1)
years = years + 1

daysRemaining = (nextDate - today).days

if self._unknown_year:
self._date = datetime(nextDate.year, nextDate.month, nextDate.day)

if daysRemaining == 0:
self._icon = self._icon_today
elif daysRemaining <= self._soon:
self._icon = self._icon_soon
else:
self._icon = self._icon_normal

self._state = daysRemaining
self._years_next = years
self._years_current = years - 1
self._weeks_remaining = int(daysRemaining / 7)

if self._show_half_anniversary:
nextHalfDate = self._half_date.date()
if today > nextHalfDate:
nextHalfDate = self._half_date.date() + relativedelta(year = today.year)
if today > nextHalfDate:
nextHalfDate = self._half_date.date() + relativedelta(year = today.year + 1)
self._half_days_remaining = (nextHalfDate - today).days
self._half_date = datetime(nextHalfDate.year, nextHalfDate.month, nextHalfDate.day)
Loading

0 comments on commit 5cbe664

Please sign in to comment.