Skip to content

Commit

Permalink
Merge pull request #323 from ic-dev21/dev
Browse files Browse the repository at this point in the history
Adding pre_cold phase
  • Loading branch information
valleedelisle authored Dec 8, 2023
2 parents 58ce8fa + f9d304c commit 7858870
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ repos:
- id: check-json
- id: no-commit-to-branch
args:
- --branch=dev
- --branch=master
- --branch=main
# - repo: https://github.com/PyCQA/pydocstyle
# rev: 5.0.2
# hooks:
Expand Down
5 changes: 5 additions & 0 deletions custom_components/hilo/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
CONF_HIGH_PERIODS,
CONF_HQ_PLAN_NAME,
CONF_LOG_TRACES,
CONF_PRE_COLD_PHASE,
CONF_TARIFF,
CONF_TRACK_UNKNOWN_SOURCES,
CONF_UNTARIFICATED_DEVICES,
Expand All @@ -59,6 +60,7 @@
DEFAULT_GENERATE_ENERGY_METERS,
DEFAULT_HQ_PLAN_NAME,
DEFAULT_LOG_TRACES,
DEFAULT_PRE_COLD_PHASE,
DEFAULT_SCAN_INTERVAL,
DEFAULT_TRACK_UNKNOWN_SOURCES,
DEFAULT_UNTARIFICATED_DEVICES,
Expand Down Expand Up @@ -220,6 +222,9 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, api: API) -> None:
self.appreciation = entry.options.get(
CONF_APPRECIATION_PHASE, DEFAULT_APPRECIATION_PHASE
)
self.pre_cold = entry.options.get(
CONF_PRE_COLD_PHASE, DEFAULT_PRE_COLD_PHASE # this is new
)
self.challenge_lock = entry.options.get(
CONF_CHALLENGE_LOCK, DEFAULT_CHALLENGE_LOCK
)
Expand Down
14 changes: 14 additions & 0 deletions custom_components/hilo/config_flow.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
CONF_GENERATE_ENERGY_METERS,
CONF_HQ_PLAN_NAME,
CONF_LOG_TRACES,
CONF_PRE_COLD_PHASE,
CONF_TRACK_UNKNOWN_SOURCES,
CONF_UNTARIFICATED_DEVICES,
DEFAULT_APPRECIATION_PHASE,
DEFAULT_CHALLENGE_LOCK,
DEFAULT_GENERATE_ENERGY_METERS,
DEFAULT_HQ_PLAN_NAME,
DEFAULT_LOG_TRACES,
DEFAULT_PRE_COLD_PHASE,
DEFAULT_SCAN_INTERVAL,
DEFAULT_TRACK_UNKNOWN_SOURCES,
DEFAULT_UNTARIFICATED_DEVICES,
Expand Down Expand Up @@ -71,6 +73,10 @@
CONF_APPRECIATION_PHASE,
default=DEFAULT_APPRECIATION_PHASE,
): cv.positive_int,
vol.Optional(
CONF_PRE_COLD_PHASE,
default=DEFAULT_PRE_COLD_PHASE,
): cv.positive_int,
vol.Optional(CONF_HQ_PLAN_NAME, default=DEFAULT_HQ_PLAN_NAME): cv.string,
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): (
vol.All(cv.positive_int, vol.Range(min=MIN_SCAN_INTERVAL))
Expand Down Expand Up @@ -238,6 +244,14 @@ async def async_step_init(
)
},
): cv.positive_int,
vol.Optional(
CONF_PRE_COLD_PHASE,
description={
"suggested_value": self.config_entry.options.get(
CONF_PRE_COLD_PHASE
)
},
): cv.positive_int,
vol.Optional(
CONF_SCAN_INTERVAL,
description={
Expand Down
5 changes: 4 additions & 1 deletion custom_components/hilo/const.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
CONF_LOG_TRACES = "log_traces"
DEFAULT_LOG_TRACES = False

CONF_PRE_COLD_PHASE = "pre_cold_phase"
DEFAULT_PRE_COLD_PHASE = 0

CONF_TRACK_UNKNOWN_SOURCES = "track_unknown_sources"
DEFAULT_TRACK_UNKNOWN_SOURCES = False

Expand All @@ -34,9 +37,9 @@

DEFAULT_SCAN_INTERVAL = 300
EVENT_SCAN_INTERVAL = 3000
REWARD_SCAN_INTERVAL = 7200
NOTIFICATION_SCAN_INTERVAL = 1800
MIN_SCAN_INTERVAL = 60
REWARD_SCAN_INTERVAL = 7200

CONF_TARIFF = {
"rate d": {
Expand Down
Empty file modified custom_components/hilo/manifest.json
100644 → 100755
Empty file.
19 changes: 16 additions & 3 deletions custom_components/hilo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ class HiloChallengeSensor(HiloEntity, RestoreEntity, SensorEntity):
- off: no ongoing or scheduled challenge
- scheduled: A challenge is scheduled, details in the next_events
extra attribute
- pre_cold: optional phase to cool further before appreciation
- appreciation: optional phase to pre-heat more before challenge
- pre_heat: Currently in the pre-heat phase
- reduction or on: Challenge is currently active, heat is lowered
- recovery: Challenge is completed, we're reheating.
Expand All @@ -617,7 +619,11 @@ def __init__(self, hilo, device, scan_interval):

@property
def state(self):
return self._state
if len(self._next_events) > 0:
event = Event(**{**{"id": 0}, **self._next_events[0]})
return event.state
else:
return "off"

@property
def icon(self):
Expand All @@ -635,6 +641,8 @@ def icon(self):
return "mdi:power-plug-off"
if self.state == "recovery":
return "mdi:calendar-check"
if self.state == "pre_cold":
return "mdi:radiator-off"
return "mdi:battery-alert"

@property
Expand Down Expand Up @@ -665,12 +673,17 @@ async def _async_update(self):
event = Event(**details)
if self._hilo.appreciation > 0:
event.appreciation(self._hilo.appreciation)

if self._hilo.pre_cold > 0:
event.pre_cold(self._hilo.pre_cold)
new_events.append(event.as_dict())
self._state = "off"

self._next_events = []

if len(new_events):
self._state = new_events[0]["state"]
self._next_events = new_events
# NOTE(ic-dev21): we don't update the state here anymore,
# since it's now calculated in the "state"


class DeviceSensor(HiloEntity, SensorEntity):
Expand Down
3 changes: 2 additions & 1 deletion custom_components/hilo/translations/en.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"log_traces": "Also log request data and websocket messages (requires debug log level on both the integration and pyhilo)",
"challenge_lock": "Lock climate entities during Hilo challenges, preventing any changes when a challenge is in progress.",
"track_unknown_sources": "Track unknown power sources in a separate energy sensor. This is a round approximation calculated when we get a reading from the Smart Energy Meter.",
"appreciation_phase": "Add an appreciation phase of X hours before the preheat phase."
"appreciation_phase": "Add an appreciation phase of X hours before the preheat phase.",
"pre_cold_phase": "Add a cooldown phase of X hours to reduce temperatures before the appreciation phase."
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion custom_components/hilo/translations/fr.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"log_traces": "Enregistrer aussi les requêtes et messages websocket (requiert le niveau de journalisation debug sur L'intégration et pyhilo)",
"challenge_lock": "Vérouiller les entités climate lors de défis Hilo, empêchant tout changement lorsqu'un défi est en cours.",
"track_unknown_sources": "Suivre des sources de consommation inconnues dans un compteur séparé. Ceci est une approximation calculée à partir de la lecture du compteur intelligent.",
"appreciation_phase": "Ajouter une période d'appréciation de X heures avant la phase de préchauffage."
"appreciation_phase": "Ajouter une période d'appréciation de X heures avant la phase de préchauffage.",
"pre_cold_phase": "Ajouter une période de refroidissement de X heures avant la phase d'appréciation."
}
}
}
Expand Down

0 comments on commit 7858870

Please sign in to comment.