Skip to content

Commit

Permalink
Merge pull request #100 from fboundy/dev
Browse files Browse the repository at this point in the history
3.6.1 - Redact sensitive info from logs
  • Loading branch information
fboundy authored Jan 31, 2024
2 parents 25c3107 + 54ca981 commit 03e3b0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PV Opt: Home Assistant Solar/Battery Optimiser v3.6.0
# PV Opt: Home Assistant Solar/Battery Optimiser v3.6.1

Solar / Battery Charging Optimisation for Home Assistant. This appDaemon application attempts to optimise charging and discharging of a home solar/battery system to minimise cost electricity cost on a daily basis using freely available solar forecast data from SolCast. This is particularly beneficial for Octopus Agile but is also benefeficial for other time-of-use tariffs such as Octopus Flux or simple Economy 7.

Expand Down
1 change: 1 addition & 0 deletions apps/pv_opt/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pv_opt:

# If true the current config in HA will be over-written with that in the config.yaml.
overwrite_ha_on_restart: true
redact_personal_data_from_log: true

consumption_history_days: 2

Expand Down
25 changes: 22 additions & 3 deletions apps/pv_opt/pv_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pvpy as pv
import numpy as np
from numpy import nan
import re


# import pvpy as pv
Expand All @@ -19,13 +20,14 @@
#
USE_TARIFF = True

VERSION = "3.6.0"
VERSION = "3.6.1"
DEBUG = False

DATE_TIME_FORMAT_LONG = "%Y-%m-%d %H:%M:%S%z"
DATE_TIME_FORMAT_SHORT = "%d-%b %H:%M"
TIME_FORMAT = "%H:%M"

REDACT_REGEX = ["[0-9]{2}m[0-9]{7}_[0-9]{13}", "a_[0-f]{8}"]

EVENT_TRIGGER = "PV_OPT"
DEBUG_TRIGGER = "PV_DEBUG"
Expand Down Expand Up @@ -276,6 +278,8 @@ def initialize(self):
# self.log(self.args)
self.inverter_type = self.args.pop("inverter_type", "SOLIS_SOLAX_MODBUS")
self.device_name = self.args.pop("device_name", "solis")
self.redact = self.args.pop("edact_personal_data_from_log", True)

self._load_inverter()

self.change_items = {}
Expand Down Expand Up @@ -328,6 +332,17 @@ def initialize(self):
f" {id} {self.handles[id]} {self.info_listen_state(self.handles[id])}"
)

def redact_for_log(self, entity_id):
if self.redact:
e = entity_id
for pattern in REDACT_REGEX:
x = re.search(pattern, e)
if x:
e = re.sub(pattern, "*" * len(x.group()), e)
return e
else:
return entity_id

def _estimate_capacity(self):
if "id_battery_charge_power" in self.config:
df = pd.DataFrame(
Expand Down Expand Up @@ -547,7 +562,9 @@ def _load_contract(self):

for imp_exp in IMPEXP:
for entity in entities[imp_exp]:
self.log(f" Found {imp_exp} entity {entity}")
self.log(
f" Found {imp_exp} entity {self.redact_for_log(entity)}"
)

tariffs = {x: None for x in IMPEXP}
for imp_exp in IMPEXP:
Expand Down Expand Up @@ -706,7 +723,9 @@ def _load_saving_events(self):
if ("octoplus_saving_session_events" in name)
][0]
self.log("")
self.log(f"Found Octopus Savings Events entity: {saving_events_entity}")
self.log(
f"Found Octopus Savings Events entity: {self.redact_for_log(saving_events_entity)}"
)

available_events = self.get_state(saving_events_entity, attribute="all")[
"attributes"
Expand Down

0 comments on commit 03e3b0c

Please sign in to comment.