Skip to content

Commit

Permalink
🐛 FIX: moved to dev
Browse files Browse the repository at this point in the history
  • Loading branch information
unl0ck committed Jul 15, 2024
1 parent 9f6723e commit 5747552
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .bumpversion-edge.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "2.8.4"
current_version = "2.8.5"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
Expand Down
41 changes: 41 additions & 0 deletions GridboxConnectorAddon-dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
<!-- https://developers.home-assistant.io/docs/add-ons/presentation#keeping-a-changelog -->
## 2.8.4

### 🚀 Added

- sensitive filter

## 2.8.0

### 🚀 Added

- Heaters with Temperature and power

### 🔨 Fixed

- does not show anymore credentials in log

## 2.7.6

### 🔨 Fixed

- if list of values is empty refresh token

## 2.7.5

### 🔨 Fixed

- Rounded to 2 decimal places

## 2.7.3

### 🔨 Fixed

- loading config.json
- check response length

## 2.7.0

### 🚀 Added

- heaters Consumption
- standalone container

## 2.6.3

Expand Down
42 changes: 27 additions & 15 deletions GridboxConnectorAddon-dev/GridboxConnector/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@
from ha_viessmann_gridbox_connector import HAViessmannGridboxConnector
import logging
from importlib.resources import files

from utils import SensitiveDataFilter
opens_file_path = '/data/options.json'
#logging.basicConfig(format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s - %(message)s', level=logging.getLevelName(os.getenv('LOG_LEVEL', 'INFO')))
logger = logging.getLogger(__name__)
logger.setLevel(logging.getLevelName(os.getenv('LOG_LEVEL', 'INFO')))
formatter = logging.Formatter('%(asctime)s %(filename)s:%(lineno)d %(levelname)s - %(message)s')
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
# Benutzerdefinierten Filter zum Logger hinzufügen
logger.addFilter(SensitiveDataFilter())

def load_gridbox_config():
config_file = files('viessmann_gridbox_connector').joinpath('config.json')
with open(str(config_file)) as json_file:
data = json.load(json_file)
return data


if __name__ == '__main__':

def run_addon():
gridbox_config = load_gridbox_config()

options_file = ''
WAIT = int(os.getenv('WAITTIME', "60"))
if os.path.exists(opens_file_path):
options_file = open(opens_file_path)
options_json = json.load(options_file)
WAIT = int(options_json["wait_time"])


options_file = open('/data/options.json')
options_json = json.load(options_file)
WAIT = int(options_json["wait_time"])
USER = os.getenv('USERNAME', "")
PASSWORD = os.environ.get('PASSWORD', "")
mqtt_user = os.getenv('MqttUser', "")
Expand All @@ -46,15 +50,23 @@ def load_gridbox_config():
gridbox_config["login"]["password"] = PASSWORD
logger.debug(gridbox_config["login"])
one_time_print = True
mqtt_settings = Settings.MQTT(host=mqtt_server, username=mqtt_user, password=mqtt_pw)
mqtt_settings = Settings.MQTT(host=mqtt_server, username=mqtt_user, password=mqtt_pw, port=mqtt_port)
viessmann_gridbox_connector = HAViessmannGridboxConnector(mqtt_settings)
gridboxConnector = GridboxConnector(gridbox_config)
while True:
measurement = gridboxConnector.retrieve_live_data()
result = measurement[0]
viessmann_gridbox_connector.update_sensors(result)
if one_time_print or logger.level == logging.DEBUG:
logger.info(result)
one_time_print = False
# Wait until fetch new values in seconds
if len(measurement) > 0:
result = measurement[0]
viessmann_gridbox_connector.update_sensors(result)
if one_time_print or logger.level == logging.DEBUG:
logger.info(result)
one_time_print = False
# Wait until fetch new values in seconds
else:
logger.warning("No data received")
gridboxConnector.init_auth()
time.sleep(WAIT)

if __name__ == '__main__':
run_addon()
#run_test_log()
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ha_mqtt_discoverable.sensors import Sensor, SensorInfo
from ha_viessmann_battery import HAViessmannBattery
from ha_viessmann_ev_charging_station import HAViessmannEVChargingStation
from ha_viessmann_heater import HAViessmannHeater


class HAViessmannGridboxConnector:
Expand All @@ -16,11 +17,13 @@ class HAViessmannGridboxConnector:
direct_consumption_household_sensor: Sensor
direct_consumption_heatpump_sensor: Sensor
direct_consumption_ev_sensor: Sensor
direct_consumption_heater_sensor: Sensor
direct_consumption_rate_sensor: Sensor
self_supply_sensor: Sensor
self_consumtion_rate_sensor: Sensor
self_sufficiency_rate_sensor: Sensor
battery_sum: HAViessmannBattery
heater_sensor: HAViessmannHeater

def __init__(self, mqtt_settings):
self.battery_sensor_dict = {}
Expand Down Expand Up @@ -76,13 +79,11 @@ def __init__(self, mqtt_settings):
self.photovoltaic_sensor = Sensor(photovoltaic_settings)

# Battery sum
self.battery_sum = HAViessmannBattery(
mqtt_settings, self.device_info, "sum", "")

self.battery_sum = HAViessmannBattery(mqtt_settings, self.device_info, "sum", "")

self.heater_sensor = HAViessmannHeater(mqtt_settings, self.device_info, "", "")
# EV
self.ev_sum = HAViessmannEVChargingStation(
mqtt_settings, self.device_info, "sum", "")
self.ev_sum = HAViessmannEVChargingStation(mqtt_settings, self.device_info, "sum", "")

# Consumption
self.consumption_household_sensor = Sensor(consumption_household_settings)
Expand Down Expand Up @@ -114,14 +115,14 @@ def update_sensors(self, measurement: dict):
if "directConsumptionEV" in measurement:
self.direct_consumption_ev_sensor.set_state(float(measurement.get("directConsumptionEV", "0")))
if "directConsumptionRate" in measurement:
self.direct_consumption_rate_sensor.set_state(float(measurement.get("directConsumptionRate", "0"))*100)
self.direct_consumption_rate_sensor.set_state(round(float(measurement.get("directConsumptionRate", "0"))*100,2))

if "selfSupply" in measurement:
self.self_supply_sensor.set_state(float(measurement.get("selfSupply", "")))
if "selfConsumptionRate" in measurement:
self.self_consumtion_rate_sensor.set_state(float(measurement.get("selfConsumptionRate", "0"))*100)
self.self_consumtion_rate_sensor.set_state(round(float(measurement.get("selfConsumptionRate", "0"))*100,2))
if "selfSufficiencyRate" in measurement:
self.self_sufficiency_rate_sensor.set_state(float(measurement.get("selfSufficiencyRate", "0"))*100)
self.self_sufficiency_rate_sensor.set_state(round(float(measurement.get("selfSufficiencyRate", "0"))*100,2))

if "battery" in measurement:
battery: dict = measurement.get("battery", {})
Expand All @@ -144,6 +145,14 @@ def update_sensors(self, measurement: dict):
remaining_charge = float(battery.get("remainingCharge", "0"))
battery_sensor.set_states(state_of_charge, capacity, power, remaining_charge)

if "heaters" in measurement:
heaters: list = measurement.get("heaters", [])
heater = heaters[0]
appliance_id = heater.get("applianceID", "")
power = round(float(heater.get("power", "0")),0)
temperature = round(float(heater.get("temperature", "0")),1)
self.heater_sensor.set_states(power, temperature)

if "evChargingStation" in measurement:
ev_charging_station: dict = measurement.get("evChargingStation", {})
power = float(ev_charging_station.get("power", "0"))
Expand Down
31 changes: 31 additions & 0 deletions GridboxConnectorAddon-dev/GridboxConnector/ha_viessmann_heater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ha_mqtt_discoverable.sensors import Sensor, SensorInfo
from ha_mqtt_discoverable import Settings, DeviceInfo


class HAViessmannHeater:
def __init__(self, mqtt_settings, device_info, name, id):
self.id: str = id
self.name: str = name
self.device_info: DeviceInfo = device_info
self.mqtt_settings: Settings.MQTT = mqtt_settings

self.heater_sensor_power = SensorInfo(
name=f"Heater {name} Power", device_class="energy", unique_id=f"gridbox_heater_power_{name}", device=device_info, unit_of_measurement="W")
self.heater_power_settings = Settings(
mqtt=mqtt_settings, entity=self.heater_sensor_power)
self.heater_power = Sensor(self.heater_power_settings)

self.heater_sensor_temperature = SensorInfo(
name=f"Heater {name} Temperature", device_class="temperature", unique_id=f"gridbox_heater_temperature_{name}", device=device_info, unit_of_measurement="C")
self.heater_temperature_settings = Settings(
mqtt=mqtt_settings, entity=self.heater_sensor_temperature)
self.heater_temperature = Sensor(self.heater_temperature_settings)


def get_name(self):
return self.name

def set_states(self, power, temperature):
self.heater_power.set_state(power)
self.heater_temperature.set_state(temperature)

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"batteries": [
{
"applianceID": "a1731af4-0399-495b-92c2-523fd61ab681",
"capacity": 10000,
"nominalCapacity": 10000,
"power": -102,
"remainingCharge": 10000,
"stateOfCharge": 1
}
],
"battery": {
"capacity": 10000,
"nominalCapacity": 10000,
"power": -102,
"remainingCharge": 10000,
"stateOfCharge": 1
},
"consumption": 847,
"directConsumption": 4523,
"directConsumptionEV": 0,
"directConsumptionHeatPump": 0,
"directConsumptionHeater": 3676,
"directConsumptionHousehold": 847,
"directConsumptionRate": 0.5465200579990334,
"grid": -3651,
"gridMeterReadingNegative": 5630400000,
"gridMeterReadingPositive": 5344920000,
"heaters": [
{
"applianceID": "12bdd8ec-9b1e-465e-8f26-feae00e5af0f",
"power": 3676,
"temperature": 70.9
}
],
"heating": 3676,
"measuredAt": "2024-07-12T12:52:47Z",
"photovoltaic": 8276,
"production": 8276,
"selfConsumption": 4625,
"selfConsumptionRate": 0.5588448525857902,
"selfSufficiencyRate": 1,
"selfSupply": 4523,
"totalConsumption": 4523
}
26 changes: 26 additions & 0 deletions GridboxConnectorAddon-dev/GridboxConnector/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import logging
import ast
class SensitiveDataFilter(logging.Filter):
def filter(self, record):
message = record.getMessage()
try:
literal_msg = ast.literal_eval(message)
# Sensible Daten filtern, falls vorhanden
if 'username' in literal_msg:
literal_msg['username'] = '***'
if 'password' in literal_msg:
literal_msg['password'] = '***'
if 'id_token' in literal_msg:
literal_msg['id_token'] = '***'
if 'access_token' in literal_msg:
literal_msg['access_token'] = '***'
if 'client_id' in literal_msg:
literal_msg['client_id'] = '***'
# Das modifizierte Dictionary zurück in einen String konvertieren
record.msg = json.dumps(literal_msg)
except json.JSONDecodeError:
# Wenn die Nachricht kein JSON ist, nichts tun
logging.error('Could not parse message as JSON')
pass
return True
2 changes: 1 addition & 1 deletion GridboxConnectorAddon-dev/cloudSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.6.3",
"version": "2.8.5",
"urls": {
"login": "https://gridx.eu.auth0.com/oauth/token",
"gateways": "https://api.gridx.de/gateways",
Expand Down
2 changes: 1 addition & 1 deletion GridboxConnectorAddon-dev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
name: Viessmann Gridbox Connector (dev)
version: "2.6.3"
version: "2.8.4"
slug: "gridbox_connector_dev"
description: Development version of Viessmann Gridbox Connector
url: "https://github.com/unl0ck/homeassistant-addon-viessmann-gridbox/tree/main/GridboxConnectorAddon-dev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export USERNAME=$(bashio::config 'username')
export PASSWORD=$(bashio::config 'password')
export LOG_LEVEL=$(bashio::config 'log_level')
ls -lash /data
cat /data/options.json
cd /build/
ls -lash
pwd
Expand Down
2 changes: 1 addition & 1 deletion GridboxConnectorAddon-dev/rootfs/share/cloudSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.6.3",
"version": "2.8.5",
"urls": {
"login": "https://gridx.eu.auth0.com/oauth/token",
"gateways": "https://api.gridx.de/gateways",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export USERNAME=$(bashio::config 'username')
export PASSWORD=$(bashio::config 'password')
export LOG_LEVEL=$(bashio::config 'log_level')
ls -lash /data
cat /data/options.json
cd /build/
ls -lash
pwd
Expand Down
2 changes: 1 addition & 1 deletion GridboxConnectorAddon-edge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- https://developers.home-assistant.io/docs/add-ons/presentation#keeping-a-changelog -->
## 2.8.2
## 2.8.4

### 🚀 Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@ def __init__(self, mqtt_settings):
self.photovoltaic_sensor = Sensor(photovoltaic_settings)

# Battery sum
self.battery_sum = HAViessmannBattery(
mqtt_settings, self.device_info, "sum", "")

self.battery_sum = HAViessmannBattery(mqtt_settings, self.device_info, "sum", "")

self.heater_sensor = HAViessmannHeater(mqtt_settings, self.device_info, "", "")
# EV
self.ev_sum = HAViessmannEVChargingStation(
mqtt_settings, self.device_info, "sum", "")
self.ev_sum = HAViessmannEVChargingStation(mqtt_settings, self.device_info, "sum", "")

# Consumption
self.consumption_household_sensor = Sensor(consumption_household_settings)
Expand Down Expand Up @@ -149,15 +147,11 @@ def update_sensors(self, measurement: dict):

if "heaters" in measurement:
heaters: list = measurement.get("heaters", [])
for heater in heaters:
appliance_id = heater.get("applianceID", "")
if self.heater_sensor is None:
self.heater_sensor = HAViessmannHeater(self.mqtt_settings, self.device_info, "", appliance_id)

power = round(float(heater.get("power", "0")),0)
temperature = round(float(heater.get("temperature", "0")),1)
self.heater_sensor.set_states(power, temperature)

heater = heaters[0]
appliance_id = heater.get("applianceID", "")
power = round(float(heater.get("power", "0")),0)
temperature = round(float(heater.get("temperature", "0")),1)
self.heater_sensor.set_states(power, temperature)

if "evChargingStation" in measurement:
ev_charging_station: dict = measurement.get("evChargingStation", {})
Expand Down
2 changes: 1 addition & 1 deletion GridboxConnectorAddon-edge/cloudSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.8.4",
"version": "2.8.5",
"urls": {
"login": "https://gridx.eu.auth0.com/oauth/token",
"gateways": "https://api.gridx.de/gateways",
Expand Down
Loading

0 comments on commit 5747552

Please sign in to comment.