summaryrefslogtreecommitdiff
path: root/src/home/database/inverter.py
blob: 8902f043ed818ad8ca7d5ea2b9a7e22de983e821 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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_discharging_current: int,
                   battery_charging_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_discharging_current,
            battery_charging_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
        ]])