Skip to content

Commit

Permalink
Merge pull request #426 from ic-dev21/Check_tarif_refactor
Browse files Browse the repository at this point in the history
Check tarif refactor
  • Loading branch information
valleedelisle authored May 4, 2024
2 parents fdd340d + 71a05e9 commit 20787cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions custom_components/hilo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ async def async_update(self) -> None:
if self.generate_energy_meters or self.track_unknown_sources:
self.check_tarif()

if self.track_unknown_sources:
self.handle_unknown_power()

def find_meter(self, hass):
entity_registry_dict = {}

Expand Down Expand Up @@ -600,6 +603,14 @@ def check_tarif(self):
LOG.debug(
f"check_tarif: Current plan: {plan_name} Target Tarif: {tarif} Energy used: {energy_used.state} Peak: {self.high_times}"
)

# ic-dev21 : make sure the select for all meters still work by moving this here
for state in self._hass.states.async_all():
entity = state.entity_id
self.set_tarif(entity, state.state, tarif)

def handle_unknown_power(self):
# ic-dev21 : new function that takes care of the unknown source meter
known_power = 0
smart_meter = self.find_meter(self._hass) # comes from find_meter function
LOG.debug(f"Smart meter used currently is: {smart_meter}")
Expand All @@ -609,9 +620,6 @@ def check_tarif(self):
if entity.endswith("hilo_rate_current"):
continue

if self.generate_energy_meters:
self.set_tarif(entity, state.state, tarif)

if entity.endswith("_power") and entity not in [
unknown_source_tracker,
smart_meter,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hilo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/dvd-dev/hilo/issues",
"requirements": ["python-hilo>=2024.4.1"],
"version": "2024.5.1"
"version": "2024.5.2"
}

0 comments on commit 20787cb

Please sign in to comment.