from .clickhouse import get_clickhouse from time import time class InverterDatabase: def __init__(self): self.db = get_clickhouse('solarmon') def add_generation(self, home_id: int, client_time: int, watts: int) -> None: self.db.execute( 'INSERT INTO generation (ClientTime, ReceivedTime, HomeID, Watts) VALUES', [[client_time, round(time()), home_id, watts]] ) def add_status(self, home_id: int, client_time: int, grid_voltage: int, grid_freq: int, ac_output_voltage: int, ac_output_freq: int, ac_output_apparent_power: int, ac_output_active_power: int, output_load_percent: int, battery_voltage: int, battery_voltage_scc: int, battery_voltage_scc2: int, battery_discharge_current: int, battery_charge_current: int, battery_capacity: int, inverter_heat_sink_temp: int, mppt1_charger_temp: int, mppt2_charger_temp: int, pv1_input_power: int, pv2_input_power: int, pv1_input_voltage: int, pv2_input_voltage: int, mppt1_charger_status: int, mppt2_charger_status: int, battery_power_direction: int, dc_ac_power_direction: int, line_power_direction: int, load_connected: int) -> None: self.db.execute("""INSERT INTO status ( ClientTime, ReceivedTime, HomeID, GridVoltage, GridFrequency, ACOutputVoltage, ACOutputFrequency, ACOutputApparentPower, ACOutputActivePower, OutputLoadPercent, BatteryVoltage, BatteryVoltageSCC, BatteryVoltageSCC2, BatteryDischargingCurrent, BatteryChargingCurrent, BatteryCapacity, HeatSinkTemp, MPPT1ChargerTemp, MPPT2ChargerTemp, PV1InputPower, PV2InputPower, PV1InputVoltage, PV2InputVoltage, MPPT1ChargerStatus, MPPT2ChargerStatus, BatteryPowerDirection, DCACPowerDirection, LinePowerDirection, LoadConnected) VALUES""", [[ client_time, round(time()), home_id, grid_voltage, grid_freq, ac_output_voltage, ac_output_freq, ac_output_apparent_power, ac_output_active_power, output_load_percent, battery_voltage, battery_voltage_scc, battery_voltage_scc2, battery_discharge_current, battery_charge_current, battery_capacity, inverter_heat_sink_temp, mppt1_charger_temp, mppt2_charger_temp, pv1_input_power, pv2_input_power, pv1_input_voltage, pv2_input_voltage, mppt1_charger_status, mppt2_charger_status, battery_power_direction, dc_ac_power_direction, line_power_direction, load_connected ]])