Skip to content

Commit

Permalink
Merge pull request #11 from krbaker/issue-8
Browse files Browse the repository at this point in the history
Fixes Issue 8
  • Loading branch information
krbaker authored Oct 3, 2021
2 parents 794063d + 273ab20 commit fbed148
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 52 deletions.
9 changes: 6 additions & 3 deletions custom_components/sunpower/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from homeassistant.const import DEVICE_CLASS_POWER
from homeassistant.components.binary_sensor import BinarySensorEntity

from .const import (
DOMAIN,
Expand All @@ -25,6 +26,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
sunpower_state = hass.data[DOMAIN][config_entry.entry_id]
_LOGGER.debug("Sunpower_state: %s", sunpower_state)

if not SUNPOWER_DESCRIPTIVE_NAMES in config_entry.data:
config_entry.data[SUNPOWER_DESCRIPTIVE_NAMES] = False
do_descriptive_names = config_entry.data[SUNPOWER_DESCRIPTIVE_NAMES]

coordinator = sunpower_state[SUNPOWER_COORDINATOR]
Expand Down Expand Up @@ -52,7 +55,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(entities, True)


class SunPowerPVSState(SunPowerPVSEntity):
class SunPowerPVSState(SunPowerPVSEntity, BinarySensorEntity):
"""Representation of SunPower PVS Working State"""

def __init__(self, coordinator, pvs_info, do_descriptive_names):
Expand Down Expand Up @@ -88,7 +91,7 @@ def is_on(self):
return self.state == WORKING_STATE


class SunPowerMeterState(SunPowerMeterEntity):
class SunPowerMeterState(SunPowerMeterEntity, BinarySensorEntity):
"""Representation of SunPower Meter Working State"""

def __init__(self, coordinator, meter_info, pvs_info, do_descriptive_names):
Expand Down Expand Up @@ -124,7 +127,7 @@ def is_on(self):
return self.state == WORKING_STATE


class SunPowerInverterState(SunPowerInverterEntity):
class SunPowerInverterState(SunPowerInverterEntity, BinarySensorEntity):
"""Representation of SunPower Inverter Working State"""

def __init__(self, coordinator, inverter_info, pvs_info, do_descriptive_names):
Expand Down
143 changes: 112 additions & 31 deletions custom_components/sunpower/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
POWER_VOLT_AMPERE,
PERCENTAGE,
ELECTRIC_POTENTIAL_VOLT,
ELECTRIC_CURRENT_AMPERE,
TEMP_CELSIUS,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_POWER_FACTOR
)

from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING
)

DOMAIN = "sunpower"

Expand All @@ -34,26 +45,41 @@
WORKING_STATE = "working"

METER_SENSORS = {
"METER_FREQUENCY": ["freq_hz", "Frequency", FREQUENCY_HERTZ, "mdi:flash"],
"METER_FREQUENCY": ["freq_hz", "Frequency", FREQUENCY_HERTZ, "mdi:flash",
None, STATE_CLASS_MEASUREMENT],
"METER_NET_KWH": [
"net_ltea_3phsum_kwh",
"Lifetime Power",
ENERGY_KILO_WATT_HOUR,
"mdi:flash",
DEVICE_CLASS_ENERGY, STATE_CLASS_TOTAL_INCREASING,
],
"METER_KW": ["p_3phsum_kw", "Power", POWER_KILO_WATT, "mdi:flash"],
"METER_VAR": ["q_3phsum_kvar", "KVA Reactive", POWER_VOLT_AMPERE, "mdi:flash"],
"METER_VA": ["s_3phsum_kva", "KVA Apparent", POWER_VOLT_AMPERE, "mdi:flash"],
"METER_POWER_FACTOR": ["tot_pf_rto", "Power Factor", PERCENTAGE, "mdi:flash"],
"METER_L1_A": ["i1_a", "Leg 1 Amps", POWER_VOLT_AMPERE, "mdi:flash"],
"METER_L2_A": ["i2_a", "Leg 2 Amps", POWER_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", ELECTRIC_POTENTIAL_VOLT, "mdi:flash"],
"METER_L2_V": ["v2n_v", "Leg 2 Volts", ELECTRIC_POTENTIAL_VOLT, "mdi:flash"],
"METER_L12_V": ["v12_v", "Supply Volts", ELECTRIC_POTENTIAL_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"]
"METER_KW": ["p_3phsum_kw", "Power", POWER_KILO_WATT, "mdi:flash",
DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT],
"METER_VAR": ["q_3phsum_kvar", "KVA Reactive", POWER_VOLT_AMPERE, "mdi:flash",
None, STATE_CLASS_MEASUREMENT],
"METER_VA": ["s_3phsum_kva", "KVA Apparent", POWER_VOLT_AMPERE, "mdi:flash",
None, STATE_CLASS_MEASUREMENT],
"METER_POWER_FACTOR": ["tot_pf_rto", "Power Factor", PERCENTAGE, "mdi:flash",
DEVICE_CLASS_POWER_FACTOR, STATE_CLASS_MEASUREMENT],
"METER_L1_A": ["i1_a", "Leg 1 Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash",
DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT],
"METER_L2_A": ["i2_a", "Leg 2 Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash",
DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT],
"METER_L1_KW": ["p1_kw", "Leg 1 KW", POWER_KILO_WATT, "mdi:flash",
DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT],
"METER_L2_KW": ["p2_kw", "Leg 2 KW", POWER_KILO_WATT, "mdi:flash",
DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT],
"METER_L1_V": ["v1n_v", "Leg 1 Volts", ELECTRIC_POTENTIAL_VOLT, "mdi:flash",
DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT],
"METER_L2_V": ["v2n_v", "Leg 2 Volts", ELECTRIC_POTENTIAL_VOLT, "mdi:flash",
DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT],
"METER_L12_V": ["v12_v", "Supply Volts", ELECTRIC_POTENTIAL_VOLT, "mdi:flash",
DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT],
"METER_TO_GRID": ["neg_ltea_3phsum_kwh", "KWH To Grid", ENERGY_KILO_WATT_HOUR, "mdi:flash",
DEVICE_CLASS_ENERGY, STATE_CLASS_TOTAL_INCREASING],
"METER_TO_HOME": ["pos_ltea_3phsum_kwh", "KWH To Home", ENERGY_KILO_WATT_HOUR, "mdi:flash",
DEVICE_CLASS_ENERGY, STATE_CLASS_TOTAL_INCREASING]
}

INVERTER_SENSORS = {
Expand All @@ -62,51 +88,106 @@
"Lifetime Power",
ENERGY_KILO_WATT_HOUR,
"mdi:flash",
DEVICE_CLASS_ENERGY,
STATE_CLASS_TOTAL_INCREASING
],
"INVERTER_KW": ["p_3phsum_kw", "Power", POWER_KILO_WATT, "mdi:flash"],
"INVERTER_VOLTS": ["vln_3phavg_v", "Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash"],
"INVERTER_AMPS": ["i_3phsum_a", "Amps", POWER_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", ELECTRIC_POTENTIAL_VOLT, "mdi:flash"],
"INVERTER_MPPT_A": ["i_mppt1_a", "MPPT Amps", POWER_VOLT_AMPERE, "mdi:flash"],
"INVERTER_KW": ["p_3phsum_kw", "Power", POWER_KILO_WATT, "mdi:flash",
DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT],
"INVERTER_VOLTS": ["vln_3phavg_v", "Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash",
DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT],
"INVERTER_AMPS": ["i_3phsum_a", "Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash",
DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT],
"INVERTER_MPPT_KW": ["p_mpptsum_kw", "MPPT KW", POWER_KILO_WATT, "mdi:flash",
DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT],
"INVERTER_MPPT1_KW": ["p_mppt1_kw", "MPPT KW", POWER_KILO_WATT, "mdi:flash",
DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT],
"INVERTER_MPPT_V": ["v_mppt1_v", "MPPT Volts", ELECTRIC_POTENTIAL_VOLT, "mdi:flash",
DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT],
"INVERTER_MPPT_A": ["i_mppt1_a", "MPPT Amps", POWER_VOLT_AMPERE, "mdi:flash",
DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT],
"INVERTER_TEMPERATURE": [
"t_htsnk_degc",
"Temperature",
TEMP_CELSIUS,
"mdi:thermometer",
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT
],
"INVERTER_FREQUENCY": ["freq_hz", "Frequency", FREQUENCY_HERTZ, "mdi:flash"],
"INVERTER_FREQUENCY": ["freq_hz", "Frequency", FREQUENCY_HERTZ, "mdi:flash",
None, STATE_CLASS_MEASUREMENT],
}

PVS_SENSORS = {
"PVS_LOAD": ["dl_cpu_load", "System Load", "", "mdi:gauge"],
"PVS_ERROR_COUNT": ["dl_err_count", "Error Count", "", "mdi:alert-circle"],
"PVS_LOAD": [
"dl_cpu_load",
"System Load",
"",
"mdi:gauge",
None,
STATE_CLASS_MEASUREMENT
],
"PVS_ERROR_COUNT": [
"dl_err_count",
"Error Count",
"",
"mdi:alert-circle",
None,
STATE_CLASS_TOTAL_INCREASING
],
"PVS_COMMUNICATION_ERRORS": [
"dl_comm_err",
"Communication Errors",
"",
"mdi:network-off",
],
None,
STATE_CLASS_TOTAL_INCREASING
],
"PVS_SKIPPED_SCANS": [
"dl_skipped_scans",
"Skipped Scans",
"",
"mdi:network-strength-off-outline",
],
"PVS_SCAN_TIME": ["dl_scan_time", "Scan Time", TIME_SECONDS, "mdi:timer-outline"],
None,
STATE_CLASS_TOTAL_INCREASING
],
"PVS_SCAN_TIME": [
"dl_scan_time",
"Scan Time",
TIME_SECONDS,
"mdi:timer-outline",
None,
STATE_CLASS_MEASUREMENT
],
"PVS_UNTRANSMITTED": [
"dl_untransmitted",
"Untransmitted Data",
"",
"mdi:radio-tower",
],
"PVS_UPTIME": ["dl_uptime", "Uptime", TIME_SECONDS, "mdi:timer-outline"],
"PVS_MEMORY_USED": ["dl_mem_used", "Memory Used", DATA_KILOBYTES, "mdi:memory"],
None,
STATE_CLASS_MEASUREMENT
],
"PVS_UPTIME": [
"dl_uptime",
"Uptime",
TIME_SECONDS,
"mdi:timer-outline",
None,
STATE_CLASS_TOTAL_INCREASING
],
"PVS_MEMORY_USED": [
"dl_mem_used",
"Memory Used",
DATA_KILOBYTES,
"mdi:memory",
None,
STATE_CLASS_MEASUREMENT
],
"PVS_FLASH_AVAILABLE": [
"dl_flash_avail",
"Flash Available",
DATA_KILOBYTES,
"mdi:memory",
],
None,
STATE_CLASS_MEASUREMENT
],
}
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.10",
"version": "0.0.11",
"domain": "sunpower",
"name": "sunpower",
"config_flow": true,
Expand Down
Loading

0 comments on commit fbed148

Please sign in to comment.