Skip to content

Commit

Permalink
Add diagnostic entities
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrMachowski committed Jan 16, 2023
1 parent 8b18624 commit 99ee503
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
42 changes: 39 additions & 3 deletions custom_components/gne_pv_monitoring/const.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import datetime

from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import (ELECTRIC_CURRENT_AMPERE, ELECTRIC_POTENTIAL_VOLT, ENERGY_WATT_HOUR, POWER_WATT,
TEMP_CELSIUS)
from homeassistant.const import (ELECTRIC_CURRENT_AMPERE, ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR,
POWER_WATT, TEMP_CELSIUS)
from homeassistant.helpers.entity import EntityCategory

NAME = "GNE PV Monitoring"
DOMAIN = "gne_pv_monitoring"
Expand Down Expand Up @@ -32,35 +33,70 @@
"unit": ELECTRIC_POTENTIAL_VOLT,
"device_class": SensorDeviceClass.VOLTAGE,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:lightning-bolt-circle",
"entity_category": None
},
"inCurrent1": {
"unit": ELECTRIC_CURRENT_AMPERE,
"device_class": SensorDeviceClass.CURRENT,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:current-dc",
"entity_category": None
},
"power1": {
"unit": POWER_WATT,
"device_class": SensorDeviceClass.POWER,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:flash",
"entity_category": None
},
"outVoltage": {
"unit": ELECTRIC_POTENTIAL_VOLT,
"device_class": SensorDeviceClass.VOLTAGE,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:lightning-bolt-circle",
"entity_category": None
},
"outCurrent": {
"unit": ELECTRIC_CURRENT_AMPERE,
"device_class": SensorDeviceClass.CURRENT,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:current-dc",
"entity_category": None
},
"dailyEnergy": {
"unit": ENERGY_WATT_HOUR,
"unit": ENERGY_KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL_INCREASING,
"icon": "mdi:solar-power",
"entity_category": None
},
"temperature": {
"unit": TEMP_CELSIUS,
"device_class": SensorDeviceClass.TEMPERATURE,
"state_class": SensorStateClass.MEASUREMENT,
"icon": "mdi:thermometer",
"entity_category": None
},
"transTime": {
"unit": None,
"device_class": None,
"state_class": None,
"icon": "mdi:clock-outline",
"entity_category": EntityCategory.DIAGNOSTIC
},
"warnCode": {
"unit": None,
"device_class": None,
"state_class": None,
"icon": "mdi:alert",
"entity_category": EntityCategory.DIAGNOSTIC
},
"status": {
"unit": None,
"device_class": None,
"state_class": None,
"icon": "mdi:solar-panel",
"entity_category": EntityCategory.DIAGNOSTIC
}
}
11 changes: 0 additions & 11 deletions custom_components/gne_pv_monitoring/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def __init__(self, entity_id, coordinator, config_entry, mac_id):
def name(self):
return f"{NAME} {self.mac_id}"


@property
def unique_id(self):
return f"{self.config_entry.entry_id}_{self.mac_id}"
Expand All @@ -28,13 +27,3 @@ def device_info(self):

def get_current_data(self) -> dict:
return self.coordinator.data[self.mac_id]

@property
def extra_state_attributes(self) -> dict:
return {
"trans_time": self.coordinator.data[self.mac_id]["transTime"]
}

@property
def icon(self):
return ICON
8 changes: 8 additions & 0 deletions custom_components/gne_pv_monitoring/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def device_class(self):
def state_class(self):
return PARAMETERS[self._parameter]["state_class"]

@property
def entity_category(self):
return PARAMETERS[self._parameter]["entity_category"]

@property
def icon(self):
return PARAMETERS[self._parameter]["icon"]

@property
def unique_id(self):
return f"{super().unique_id}_sensor_{self._parameter}"

0 comments on commit 99ee503

Please sign in to comment.