From 1facae0b48c54fb006ac1e7ad654f6254419ff1b Mon Sep 17 00:00:00 2001 From: Isaac Velando Date: Fri, 5 Jan 2024 09:09:35 -0600 Subject: [PATCH] Remove /api/devices/vitals queries as FW 23.44.0 removes this; for details see jasonacox/pypowerwall/issues/57 --- connect/connect.go | 13 --- influxdb/influxdb.go | 228 ------------------------------------------- model/model.go | 219 ----------------------------------------- 3 files changed, 460 deletions(-) diff --git a/connect/connect.go b/connect/connect.go index 6c820f9..7184d46 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -342,19 +342,6 @@ func GetAll(conf *config.Configuration, client *http.Client) (model.Teg, error) teg.SystemStateOfEnergy.Timestamp = time.Now() }(&wg) - wg.Add(1) - go func(waitgroup *sync.WaitGroup) { - defer waitgroup.Done() - endpoint := "/api/devices/vitals" - err := GetEndpoint(conf, client, endpoint, &teg.DevicesVitals.DevicesVitalsProto) - if err != nil { - errChan <- fmt.Errorf("error when querying %s, %s", endpoint, err) - return - } - teg.DevicesVitals.Timestamp = time.Now() - teg.DevicesVitals.Transform() - }(&wg) - go func() { wg.Wait() close(errChan) diff --git a/influxdb/influxdb.go b/influxdb/influxdb.go index 726302a..b2b712b 100644 --- a/influxdb/influxdb.go +++ b/influxdb/influxdb.go @@ -439,234 +439,6 @@ func WriteAll(conf *config.Configuration, writeAPI influxAPI.WriteAPI, metrics m writeAPI.WritePoint(p) } - // Solar device information - for _, inverter := range metrics.DevicesVitals.DevicesVitals.Inverters { - p = influx.NewPoint( - conf.InfluxDB.MeasurementPrefix+"energy_inverters", - map[string]string{ - "gateway_id": metrics.Status.GatewayID, - "firmware_version": metrics.Status.FirmwareVersion, - "firmware_git_hash": metrics.Status.FirmwareGitHash, - "sync_type": metrics.Status.SyncType, - "site_name": metrics.SiteInfo.SiteName, - "site_grid_code": metrics.SiteInfo.GridCode.GridCode, - "site_country": metrics.SiteInfo.GridCode.Country, - "site_state": metrics.SiteInfo.GridCode.State, - "site_utility": metrics.SiteInfo.GridCode.Utility, - "din": inverter.Din, - "part_number": inverter.PartNumber, - "serial_number": inverter.SerialNumber, - "manufacturer": inverter.Manufacturer, - "parent_din": inverter.ComponentParentDin, - "inverter_firmware_version": inverter.FirmwareVersion, - "ecu_type": inverter.EcuType, - }, - map[string]interface{}{ - "pvac_vl1_ground": inverter.PvacVL1Ground, - "pvac_vl2_ground": inverter.PvacVL2Ground, - "pvac_v_hv_minus_chassis_dc": inverter.PvacVHvMinusChassisDC, - "pvac_lifetime_energy_pv_total": inverter.PvacLifetimeEnergyPvTotal, - "pvac_i_out": inverter.PvacIOut, - "pvac_v_out": inverter.PvacVOut, - "pvac_f_out": inverter.PvacFOut, - "pvac_p_out": inverter.PvacPOut, - "pvac_q_out": inverter.PvacQOut, - "pvac_state": inverter.PvacState, - "pvac_grid_state": inverter.PvacGridState, - "pvac_inv_state": inverter.PvacInvState, - "pvi_power_status_setpoint": inverter.PviPowerStatusSetpoint, - }, - metrics.DevicesVitals.Timestamp) - - writeAPI.WritePoint(p) - - p = influx.NewPoint( - conf.InfluxDB.MeasurementPrefix+"energy_inverters", - map[string]string{ - "gateway_id": metrics.Status.GatewayID, - "firmware_version": metrics.Status.FirmwareVersion, - "firmware_git_hash": metrics.Status.FirmwareGitHash, - "sync_type": metrics.Status.SyncType, - "site_name": metrics.SiteInfo.SiteName, - "site_grid_code": metrics.SiteInfo.GridCode.GridCode, - "site_country": metrics.SiteInfo.GridCode.Country, - "site_state": metrics.SiteInfo.GridCode.State, - "site_utility": metrics.SiteInfo.GridCode.Utility, - "din": inverter.Din, - "part_number": inverter.PartNumber, - "serial_number": inverter.SerialNumber, - "manufacturer": inverter.Manufacturer, - "parent_din": inverter.ComponentParentDin, - "inverter_firmware_version": inverter.FirmwareVersion, - "ecu_type": inverter.EcuType, - "string_id": "A", - }, - map[string]interface{}{ - "pvac_pv_state": inverter.PvacPvStateA, - "pvac_pv_current": inverter.PvacPvCurrentA, - "pvac_pv_measured_voltage": inverter.PvacPvMeasuredVoltageA, - "pvac_pv_measured_power": inverter.PvacPvMeasuredPowerA, - }, - metrics.DevicesVitals.Timestamp) - - writeAPI.WritePoint(p) - - p = influx.NewPoint( - conf.InfluxDB.MeasurementPrefix+"energy_inverters", - map[string]string{ - "gateway_id": metrics.Status.GatewayID, - "firmware_version": metrics.Status.FirmwareVersion, - "firmware_git_hash": metrics.Status.FirmwareGitHash, - "sync_type": metrics.Status.SyncType, - "site_name": metrics.SiteInfo.SiteName, - "site_grid_code": metrics.SiteInfo.GridCode.GridCode, - "site_country": metrics.SiteInfo.GridCode.Country, - "site_state": metrics.SiteInfo.GridCode.State, - "site_utility": metrics.SiteInfo.GridCode.Utility, - "din": inverter.Din, - "part_number": inverter.PartNumber, - "serial_number": inverter.SerialNumber, - "manufacturer": inverter.Manufacturer, - "parent_din": inverter.ComponentParentDin, - "inverter_firmware_version": inverter.FirmwareVersion, - "ecu_type": inverter.EcuType, - "string_id": "B", - }, - map[string]interface{}{ - "pvac_pv_state": inverter.PvacPvStateB, - "pvac_pv_current": inverter.PvacPvCurrentB, - "pvac_pv_measured_voltage": inverter.PvacPvMeasuredVoltageB, - "pvac_pv_measured_power": inverter.PvacPvMeasuredPowerB, - }, - metrics.DevicesVitals.Timestamp) - - writeAPI.WritePoint(p) - - p = influx.NewPoint( - conf.InfluxDB.MeasurementPrefix+"energy_inverters", - map[string]string{ - "gateway_id": metrics.Status.GatewayID, - "firmware_version": metrics.Status.FirmwareVersion, - "firmware_git_hash": metrics.Status.FirmwareGitHash, - "sync_type": metrics.Status.SyncType, - "site_name": metrics.SiteInfo.SiteName, - "site_grid_code": metrics.SiteInfo.GridCode.GridCode, - "site_country": metrics.SiteInfo.GridCode.Country, - "site_state": metrics.SiteInfo.GridCode.State, - "site_utility": metrics.SiteInfo.GridCode.Utility, - "din": inverter.Din, - "part_number": inverter.PartNumber, - "serial_number": inverter.SerialNumber, - "manufacturer": inverter.Manufacturer, - "parent_din": inverter.ComponentParentDin, - "inverter_firmware_version": inverter.FirmwareVersion, - "ecu_type": inverter.EcuType, - "string_id": "C", - }, - map[string]interface{}{ - "pvac_pv_state": inverter.PvacPvStateC, - "pvac_pv_current": inverter.PvacPvCurrentC, - "pvac_pv_measured_voltage": inverter.PvacPvMeasuredVoltageC, - "pvac_pv_measured_power": inverter.PvacPvMeasuredPowerC, - }, - metrics.DevicesVitals.Timestamp) - - writeAPI.WritePoint(p) - - p = influx.NewPoint( - conf.InfluxDB.MeasurementPrefix+"energy_inverters", - map[string]string{ - "gateway_id": metrics.Status.GatewayID, - "firmware_version": metrics.Status.FirmwareVersion, - "firmware_git_hash": metrics.Status.FirmwareGitHash, - "sync_type": metrics.Status.SyncType, - "site_name": metrics.SiteInfo.SiteName, - "site_grid_code": metrics.SiteInfo.GridCode.GridCode, - "site_country": metrics.SiteInfo.GridCode.Country, - "site_state": metrics.SiteInfo.GridCode.State, - "site_utility": metrics.SiteInfo.GridCode.Utility, - "din": inverter.Din, - "part_number": inverter.PartNumber, - "serial_number": inverter.SerialNumber, - "manufacturer": inverter.Manufacturer, - "parent_din": inverter.ComponentParentDin, - "inverter_firmware_version": inverter.FirmwareVersion, - "ecu_type": inverter.EcuType, - "string_id": "D", - }, - map[string]interface{}{ - "pvac_pv_state": inverter.PvacPvStateD, - "pvac_pv_current": inverter.PvacPvCurrentD, - "pvac_pv_measured_voltage": inverter.PvacPvMeasuredVoltageD, - "pvac_pv_measured_power": inverter.PvacPvMeasuredPowerD, - }, - metrics.DevicesVitals.Timestamp) - - writeAPI.WritePoint(p) - } - - for _, temperature := range metrics.DevicesVitals.DevicesVitals.Temperatures { - // Device temperature information - p = influx.NewPoint( - conf.InfluxDB.MeasurementPrefix+"energy_devices", - map[string]string{ - "gateway_id": metrics.Status.GatewayID, - "firmware_version": metrics.Status.FirmwareVersion, - "firmware_git_hash": metrics.Status.FirmwareGitHash, - "sync_type": metrics.Status.SyncType, - "site_name": metrics.SiteInfo.SiteName, - "site_grid_code": metrics.SiteInfo.GridCode.GridCode, - "site_country": metrics.SiteInfo.GridCode.Country, - "site_state": metrics.SiteInfo.GridCode.State, - "site_utility": metrics.SiteInfo.GridCode.Utility, - "din": temperature.Din, - "part_number": temperature.PartNumber, - "serial_number": temperature.SerialNumber, - "manufacturer": temperature.Manufacturer, - "parent_din": temperature.ComponentParentDin, - "device_firmware_version": temperature.FirmwareVersion, - "ecu_type": temperature.EcuType, - }, - map[string]interface{}{ - "thc_state": temperature.ThcState, - "thc_ambient_temp": temperature.ThcAmbientTemp, - }, - metrics.DevicesVitals.Timestamp) - - writeAPI.WritePoint(p) - } - - // Device alerts information - for _, alertingDevice := range metrics.DevicesVitals.DevicesVitals.Alerts { - alerts := make(map[string]interface{}) - for _, alert := range alertingDevice.Alerts { - alerts["alert_"+alert] = true - } - p = influx.NewPoint( - conf.InfluxDB.MeasurementPrefix+"energy_devices", - map[string]string{ - "gateway_id": metrics.Status.GatewayID, - "firmware_version": metrics.Status.FirmwareVersion, - "firmware_git_hash": metrics.Status.FirmwareGitHash, - "sync_type": metrics.Status.SyncType, - "site_name": metrics.SiteInfo.SiteName, - "site_grid_code": metrics.SiteInfo.GridCode.GridCode, - "site_country": metrics.SiteInfo.GridCode.Country, - "site_state": metrics.SiteInfo.GridCode.State, - "site_utility": metrics.SiteInfo.GridCode.Utility, - "din": alertingDevice.Din, - "part_number": alertingDevice.PartNumber, - "serial_number": alertingDevice.SerialNumber, - "manufacturer": alertingDevice.Manufacturer, - "parent_din": alertingDevice.ComponentParentDin, - "device_firmware_version": alertingDevice.FirmwareVersion, - }, - alerts, - metrics.DevicesVitals.Timestamp) - - writeAPI.WritePoint(p) - } - // System status grid fault readings var valueString string for _, fault := range metrics.SystemStatus.GridFaults { diff --git a/model/model.go b/model/model.go index d9b1cff..3da872f 100644 --- a/model/model.go +++ b/model/model.go @@ -2,7 +2,6 @@ package model import ( "encoding/json" - "strconv" "time" ) @@ -58,7 +57,6 @@ type Teg struct { SystemStatus TegSystemStatus SystemGridStatus TegSystemGridStatus SystemStateOfEnergy TegSystemStateOfEnergy - DevicesVitals TegDevicesVitals } // TegMeters defines the response for /api/meters/aggregates @@ -582,220 +580,3 @@ type TegSystemStateOfEnergy struct { Percentage float64 `json:"percentage"` } -// TegDevicesVitals defines the response for /api/devices/vitals -type TegDevicesVitals struct { - Timestamp time.Time - DevicesVitalsProto DevicesWithVitals - DevicesVitals TegDevices -} - -// TegDevices defines the transformed device vitals meant for database ingest -type TegDevices struct { - Inverters []TegDeviceInverters - Temperatures []TegDeviceTemperatures - Alerts []TegDeviceAlerts -} - -// TegDeviceInverters defines inverter data underneath TegDevices -type TegDeviceInverters struct { - Din string - PartNumber string - SerialNumber string - Manufacturer string - ComponentParentDin string - FirmwareVersion string - EcuType string - LastCommunicationTime time.Time - PvacVL1Ground float64 - PvacVL2Ground float64 - PvacVHvMinusChassisDC float64 - PvacLifetimeEnergyPvTotal float64 - PvacIOut float64 - PvacVOut float64 - PvacFOut float64 - PvacPOut float64 - PvacQOut float64 - PvacState string - PvacGridState string - PvacInvState string - PviPowerStatusSetpoint string - PvacPvStateA string - PvacPvStateB string - PvacPvStateC string - PvacPvStateD string - PvacPvCurrentA float64 - PvacPvCurrentB float64 - PvacPvCurrentC float64 - PvacPvCurrentD float64 - PvacPvMeasuredVoltageA float64 - PvacPvMeasuredVoltageB float64 - PvacPvMeasuredVoltageC float64 - PvacPvMeasuredVoltageD float64 - PvacPvMeasuredPowerA float64 - PvacPvMeasuredPowerB float64 - PvacPvMeasuredPowerC float64 - PvacPvMeasuredPowerD float64 -} - -// TegDeviceTemperatures defines thermal data underneath TegDevices -type TegDeviceTemperatures struct { - Din string - PartNumber string - SerialNumber string - Manufacturer string - ComponentParentDin string - FirmwareVersion string - EcuType string - LastCommunicationTime time.Time - ThcState string - ThcAmbientTemp float64 -} - -// TegDeviceAlerts defines alert data underneath TegDevices -type TegDeviceAlerts struct { - Din string - PartNumber string - SerialNumber string - Manufacturer string - ComponentParentDin string - FirmwareVersion string - LastCommunicationTime time.Time - Alerts []string -} - -// Transform parses data responses from TegDevicesVitals to prepare it for TegDevices -func (r *TegDevicesVitals) Transform() { - - // Transform pv string data - for _, devices := range r.DevicesVitalsProto.Devices { - device := devices.Device - attribute := device.Device.DeviceAttributes - ecuAttributes := attribute.GetTeslaEnergyEcuAttributes() - if ecuAttributes != nil && ecuAttributes.GetEcuType() == 296 { - stringData := TegDeviceInverters{} - stringData.Din = device.Device.Din.GetValue() - stringData.PartNumber = device.Device.PartNumber.GetValue() - stringData.SerialNumber = device.Device.SerialNumber.GetValue() - stringData.Manufacturer = device.Device.Manufacturer.GetValue() - stringData.ComponentParentDin = device.Device.ComponentParentDin.GetValue() - stringData.FirmwareVersion = device.Device.FirmwareVersion.GetValue() - stringData.EcuType = strconv.Itoa(int(ecuAttributes.GetEcuType())) - stringData.LastCommunicationTime = device.Device.LastCommunicationTime.AsTime() - for _, vital := range devices.Vitals { - stringData.getStringVital(*vital) - } - r.DevicesVitals.Inverters = append(r.DevicesVitals.Inverters, stringData) - } - } - - // Transform temperature data - for _, devices := range r.DevicesVitalsProto.Devices { - device := devices.Device - attribute := device.Device.DeviceAttributes - ecuAttributes := attribute.GetTeslaEnergyEcuAttributes() - if ecuAttributes != nil && ecuAttributes.GetEcuType() == 224 { - tempData := TegDeviceTemperatures{} - tempData.Din = device.Device.Din.GetValue() - tempData.PartNumber = device.Device.PartNumber.GetValue() - tempData.SerialNumber = device.Device.SerialNumber.GetValue() - tempData.Manufacturer = device.Device.Manufacturer.GetValue() - tempData.ComponentParentDin = device.Device.ComponentParentDin.GetValue() - tempData.FirmwareVersion = device.Device.FirmwareVersion.GetValue() - tempData.EcuType = strconv.Itoa(int(ecuAttributes.GetEcuType())) - tempData.LastCommunicationTime = device.Device.LastCommunicationTime.AsTime() - for _, vital := range devices.Vitals { - tempData.getTempVital(*vital) - } - r.DevicesVitals.Temperatures = append(r.DevicesVitals.Temperatures, tempData) - } - } - - // Transform alerts data - for _, devices := range r.DevicesVitalsProto.Devices { - if len(devices.Alerts) > 0 { - device := devices.Device - alertData := TegDeviceAlerts{} - alertData.Din = device.Device.Din.GetValue() - alertData.PartNumber = device.Device.PartNumber.GetValue() - alertData.SerialNumber = device.Device.SerialNumber.GetValue() - alertData.Manufacturer = device.Device.Manufacturer.GetValue() - alertData.ComponentParentDin = device.Device.ComponentParentDin.GetValue() - alertData.FirmwareVersion = device.Device.FirmwareVersion.GetValue() - alertData.LastCommunicationTime = device.Device.LastCommunicationTime.AsTime() - alertData.Alerts = devices.Alerts - r.DevicesVitals.Alerts = append(r.DevicesVitals.Alerts, alertData) - } - } -} - -func (r *TegDeviceInverters) getStringVital(v DeviceVital) { - switch *v.Name { - case "PVAC_Iout": - r.PvacIOut = v.GetFloatValue() - case "PVAC_VL1Ground": - r.PvacVL1Ground = v.GetFloatValue() - case "PVAC_VL2Ground": - r.PvacVL2Ground = v.GetFloatValue() - case "PVAC_VHvMinusChassisDC": - r.PvacVHvMinusChassisDC = v.GetFloatValue() - case "PVAC_LifetimeEnergyPV_Total": - r.PvacLifetimeEnergyPvTotal = v.GetFloatValue() - case "PVAC_Vout": - r.PvacVOut = v.GetFloatValue() - case "PVAC_Fout": - r.PvacFOut = v.GetFloatValue() - case "PVAC_Pout": - r.PvacPOut = v.GetFloatValue() - case "PVAC_Qout": - r.PvacQOut = v.GetFloatValue() - case "PVAC_State": - r.PvacState = v.GetStringValue() - case "PVAC_GridState": - r.PvacGridState = v.GetStringValue() - case "PVAC_InvState": - r.PvacInvState = v.GetStringValue() - case "PVI-PowerStatusSetpoint": - r.PviPowerStatusSetpoint = v.GetStringValue() - case "PVAC_PvState_A": - r.PvacPvStateA = v.GetStringValue() - case "PVAC_PvState_B": - r.PvacPvStateB = v.GetStringValue() - case "PVAC_PvState_C": - r.PvacPvStateC = v.GetStringValue() - case "PVAC_PvState_D": - r.PvacPvStateD = v.GetStringValue() - case "PVAC_PVCurrent_A": - r.PvacPvCurrentA = v.GetFloatValue() - case "PVAC_PVCurrent_B": - r.PvacPvCurrentB = v.GetFloatValue() - case "PVAC_PVCurrent_C": - r.PvacPvCurrentC = v.GetFloatValue() - case "PVAC_PVCurrent_D": - r.PvacPvCurrentD = v.GetFloatValue() - case "PVAC_PVMeasuredVoltage_A": - r.PvacPvMeasuredVoltageA = v.GetFloatValue() - case "PVAC_PVMeasuredVoltage_B": - r.PvacPvMeasuredVoltageB = v.GetFloatValue() - case "PVAC_PVMeasuredVoltage_C": - r.PvacPvMeasuredVoltageC = v.GetFloatValue() - case "PVAC_PVMeasuredVoltage_D": - r.PvacPvMeasuredVoltageD = v.GetFloatValue() - case "PVAC_PVMeasuredPower_A": - r.PvacPvMeasuredPowerA = v.GetFloatValue() - case "PVAC_PVMeasuredPower_B": - r.PvacPvMeasuredPowerB = v.GetFloatValue() - case "PVAC_PVMeasuredPower_C": - r.PvacPvMeasuredPowerC = v.GetFloatValue() - case "PVAC_PVMeasuredPower_D": - r.PvacPvMeasuredPowerD = v.GetFloatValue() - } -} - -func (r *TegDeviceTemperatures) getTempVital(v DeviceVital) { - switch *v.Name { - case "THC_State": - r.ThcState = v.GetStringValue() - case "THC_AmbientTemp": - r.ThcAmbientTemp = v.GetFloatValue() - } -}