Skip to content

Commit

Permalink
fixed for PVS6, added new fieds and now more tolerant of missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
krbaker committed Jun 19, 2021
1 parent 6fd1667 commit baa186e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
10 changes: 10 additions & 0 deletions custom_components/sunpower/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
"METER_VAR": ["q_3phsum_kvar", "KVA Reactive", ELECTRICAL_VOLT_AMPERE, "mdi:flash"],
"METER_VA": ["s_3phsum_kva", "KVA Apparent", ELECTRICAL_VOLT_AMPERE, "mdi:flash"],
"METER_POWER_FACTOR": ["tot_pf_rto", "Power Factor", PERCENTAGE, "mdi:flash"],
"METER_L1_A": ["i1_a", "Leg 1 Amps", ELECTRICAL_VOLT_AMPERE, "mdi:flash"],
"METER_L2_A": ["i2_a", "Leg 2 Amps", ELECTRICAL_VOLT_AMPERE, "mdi:flash"],
"METER_L1_KW": ["p1_kw", "Leg 1 KW", POWER_KILO_WATT, "mdi:flash"],
"METER_L2_KW": ["p2_kw", "Leg 2 KW", POWER_KILO_WATT, "mdi:flash"],
"METER_L1_V": ["v1n_v", "Leg 1 Volts", VOLT, "mdi:flash"],
"METER_L2_V": ["v2n_v", "Leg 2 Volts", VOLT, "mdi:flash"],
"METER_L12_V": ["v12_v", "Supply Volts", VOLT, "mdi:flash"],
"METER_TO_GRID": ["neg_ltea_3phsum_kwh", "KWH To Grid", ENERGY_KILO_WATT_HOUR, "mdi:flash"],
"METER_TO_HOME": ["pos_ltea_3phsum_kwh", "KWH To Home", ENERGY_KILO_WATT_HOUR, "mdi:flash"]
}

INVERTER_SENSORS = {
Expand All @@ -59,6 +68,7 @@
"INVERTER_VOLTS": ["vln_3phavg_v", "Voltage", VOLT, "mdi:flash"],
"INVERTER_AMPS": ["i_3phsum_a", "Amps", ELECTRICAL_VOLT_AMPERE, "mdi:flash"],
"INVERTER_MPPT_KW": ["p_mpptsum_kw", "MPPT KW", POWER_KILO_WATT, "mdi:flash"],
"INVERTER_MPPT1_KW": ["p_mppt1_kw", "MPPT KW", POWER_KILO_WATT, "mdi:flash"],
"INVERTER_MPPT_V": ["v_mppt1_v", "MPPT Volts", VOLT, "mdi:flash"],
"INVERTER_MPPT_A": ["i_mppt1_a", "MPPT Amps", ELECTRICAL_VOLT_AMPERE, "mdi:flash"],
"INVERTER_TEMPERATURE": [
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sunpower/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.7",
"version": "0.0.8",
"domain": "sunpower",
"name": "sunpower",
"config_flow": true,
Expand Down
69 changes: 39 additions & 30 deletions custom_components/sunpower/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,59 @@ async def async_setup_entry(hass, config_entry, async_add_entities):

entities = []
for sensor in PVS_SENSORS:
entities.append(
SunPowerPVSBasic(
coordinator,
pvs,
PVS_SENSORS[sensor][0],
PVS_SENSORS[sensor][1],
PVS_SENSORS[sensor][2],
PVS_SENSORS[sensor][3],
)
spb = SunPowerPVSBasic(
coordinator,
pvs,
PVS_SENSORS[sensor][0],
PVS_SENSORS[sensor][1],
PVS_SENSORS[sensor][2],
PVS_SENSORS[sensor][3],
)
try:
spb.state
entities.append(spb)
except KeyError:
pass

if METER_DEVICE_TYPE not in sunpower_data:
_LOGGER.error("Cannot find any power meters")
else:
for data in sunpower_data[METER_DEVICE_TYPE].values():
for sensor in METER_SENSORS:
entities.append(
SunPowerMeterBasic(
coordinator,
data,
pvs,
METER_SENSORS[sensor][0],
METER_SENSORS[sensor][1],
METER_SENSORS[sensor][2],
METER_SENSORS[sensor][3],
)
smb = SunPowerMeterBasic(
coordinator,
data,
pvs,
METER_SENSORS[sensor][0],
METER_SENSORS[sensor][1],
METER_SENSORS[sensor][2],
METER_SENSORS[sensor][3],
)
try:
smb.state
entities.append(smb)
except KeyError:
pass

if INVERTER_DEVICE_TYPE not in sunpower_data:
_LOGGER.error("Cannot find any power inverters")
else:
for data in sunpower_data[INVERTER_DEVICE_TYPE].values():
for sensor in INVERTER_SENSORS:
entities.append(
SunPowerInverterBasic(
coordinator,
data,
pvs,
INVERTER_SENSORS[sensor][0],
INVERTER_SENSORS[sensor][1],
INVERTER_SENSORS[sensor][2],
INVERTER_SENSORS[sensor][3],
)
sib = SunPowerInverterBasic(
coordinator,
data,
pvs,
INVERTER_SENSORS[sensor][0],
INVERTER_SENSORS[sensor][1],
INVERTER_SENSORS[sensor][2],
INVERTER_SENSORS[sensor][3],
)
try:
sib.state
entities.append(sib)
except KeyError:
pass

async_add_entities(entities, True)

Expand All @@ -93,7 +102,7 @@ def __init__(self, coordinator, pvs_info, field, title, unit, icon):
self._field = field
self._unit = unit
self._icon = icon

@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
Expand Down

0 comments on commit baa186e

Please sign in to comment.