Skip to content

Commit

Permalink
remove country from hacs.json
Browse files Browse the repository at this point in the history
def state -> def native_value
  • Loading branch information
marq24 authored and marq24 committed Sep 5, 2024
1 parent 7d4c52b commit f5e1d0a
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 52 deletions.
11 changes: 5 additions & 6 deletions custom_components/goecharger_api2/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from typing import Final

from custom_components.goecharger_api2.pygoecharger_ha.keys import Tag, IS_TRIGGER
from homeassistant.components.binary_sensor import BinarySensorEntityDescription, BinarySensorDeviceClass
from homeassistant.components.button import ButtonEntityDescription
from homeassistant.components.number import NumberEntityDescription, NumberDeviceClass, NumberMode
Expand All @@ -12,8 +13,6 @@
UnitOfFrequency, UnitOfElectricPotential, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS
)

from custom_components.goecharger_api2.pygoecharger_ha.keys import Tag, IS_TRIGGER

# Base component constants
MANUFACTURER: Final = "go-e GmbH [Austria]"
NAME: Final = "go-eCharger APIv2 Connect"
Expand Down Expand Up @@ -981,8 +980,8 @@ class ExtSwitchEntityDescription(SwitchEntityDescription):
key=Tag.CLL.key,
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=None,
state_class=SensorStateClass.MEASUREMENT,
device_class=None,
state_class=None,
device_class=SensorDeviceClass.ENUM,
icon="mdi:list-status",
entity_registry_enabled_default=True
),
Expand Down Expand Up @@ -1527,8 +1526,8 @@ class ExtSwitchEntityDescription(SwitchEntityDescription):
key=Tag.MAP.key,
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=None,
state_class=SensorStateClass.MEASUREMENT,
device_class=None,
state_class=None,
device_class=SensorDeviceClass.ENUM,
icon="mdi:vector-triangle",
entity_registry_enabled_default=True
),
Expand Down
2 changes: 1 addition & 1 deletion custom_components/goecharger_api2/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-goecharger-api2/issues",
"requirements": [],
"version": "2024.8.1"
"version": "2024.9.0"
}
2 changes: 2 additions & 0 deletions custom_components/goecharger_api2/pygoecharger_ha/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

# found api-keys that are not documented (yet) ?!
FILTER_UNKNOWN_COMON: Final = "aus,ccd,cle,clea,cmmr,cmp,cms,csa,ct,ctrls,data,di1,die,dii,dll,hai,hla,isgo,la1,la3,lbl,lopr,lrc,lri,lrr,lwf,ocppao,ocppcm,ocppcs,ocppf,ocppla,ocpplo,ocppti,pdi,pgr,rde,smd,tcl,tsi,tzt,ufa,ufe,ufm,ufs,wbw,wda,wsl"

FILTER_UNKNOWN_FW59_X_BETA: Final = "bar,dsrc,evt,gmtr,gsa,lto,mhe,mht,ocppdp,ocppmp,ocpptp,orsch,pco,rdbfe,rdbse,rdefe,rdese,rdple,rdree,rmaf,rmav,rmif,rmiv,rsa,rsre,rsrr,tab"
FILTER_UNKNOWN_FW56_2_BETA: Final = "bar,gmtr,gsa,mhe,mht,pco,rmaf,rmav,rmif,rmiv,rsa,rsre,rsrr"
FILTER_UNKNOWN_FW56_1: Final = "avgfhz,simo"

Expand Down
94 changes: 52 additions & 42 deletions custom_components/goecharger_api2/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from datetime import datetime, time
from typing import Final

from homeassistant.components.sensor import SensorEntity
from custom_components.goecharger_api2.pygoecharger_ha.keys import Tag
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity

from custom_components.goecharger_api2.pygoecharger_ha.keys import Tag
from . import GoeChargerDataUpdateCoordinator, GoeChargerBaseEntity
from .const import DOMAIN, SENSOR_SENSORS, ExtSensorEntityDescription

Expand Down Expand Up @@ -40,7 +39,17 @@ def _camel_to_snake(a_key: str):

@property
def state(self):
"""Return the state of the sensor."""
# for SensorDeviceClass.DATE we will use out OWN 'state' render impl
if self.entity_description.device_class == SensorDeviceClass.DATE:
value = self.native_value
if value is None:
value = "unknown"
return value
else:
return SensorEntity.state.fget(self)

@property
def native_value(self):
try:
if self.entity_description.idx is not None:
value = self.coordinator.data[self.data_key][self.entity_description.idx]
Expand All @@ -59,49 +68,50 @@ def state(self):
else:
value = self.coordinator.data[self.data_key]

if value is None or value == "":
value = "unknown"
else:
if self.entity_description.lookup is not None:
if self.data_key.lower() in self.coordinator.lang_map:
value = self.coordinator.lang_map[self.data_key.lower()][value]
else:
_LOGGER.warning(f"{self.data_key} not found in translations")

is_int_value = isinstance(value, int)

# the timestamp values of the go-eCharger are based on the reboot time stamp...
# so we have to subtract these values!
if is_int_value and self.entity_description.differential_base_key is not None:
differential_base = self.coordinator.data[self.entity_description.differential_base_key]
if differential_base is not None and int(differential_base) > 0:
value = differential_base - int(value)

if self.entity_description.factor is not None and self.entity_description.factor > 0:
if is_int_value:
value = int(value/self.entity_description.factor)
if value is None or len(str(value)) == 0:
value = None
else:
if self.entity_description.lookup is not None:
if self.data_key.lower() in self.coordinator.lang_map:
value = self.coordinator.lang_map[self.data_key.lower()][value]
else:
_LOGGER.warning(f"{self.data_key} not found in translations")
else:
value = value/self.entity_description.factor

if isinstance(value, datetime):
return value.isoformat(sep=' ', timespec="minutes")
elif isinstance(value, time):
return value.isoformat(timespec="minutes")
elif self.entity_description.suggested_display_precision is not None:
value = round(float(value), self.entity_description.suggested_display_precision)
# self.entity_description.lookup values are always 'strings' - so there we should not
# have an additional features like 'factor' or 'differential_base_key'
is_int_value = isinstance(value, int)

# the timestamp values of the go-eCharger are based on the reboot time stamp...
# so we have to subtract these values!
if is_int_value and self.entity_description.differential_base_key is not None:
differential_base = self.coordinator.data[self.entity_description.differential_base_key]
if differential_base is not None and int(differential_base) > 0:
value = differential_base - int(value)

if self.entity_description.factor is not None and self.entity_description.factor > 0:
if is_int_value:
value = int(value/self.entity_description.factor)
else:
value = value/self.entity_description.factor

if isinstance(value, datetime):
return value.isoformat(sep=' ', timespec="minutes")
elif isinstance(value, time):
return value.isoformat(timespec="minutes")
elif isinstance(value, bool):
if value is True:
value = "on"
elif value is False:
value = "off"

except IndexError:
if self.entity_description.lookup is not None:
_LOGGER.debug(f"lc-key: {self.data_key.lower()} value: {value} -> {self.coordinator.lang_map[self.data_key.lower()]}")
else:
_LOGGER.debug(f"lc-key: {self.data_key.lower()} caused IndexError")
value = "unknown"
except KeyError:
value = "unknown"
except TypeError:
return "unknown"
if value is True:
value = "on"
elif value is False:
value = "off"
value = None
except (KeyError, TypeError):
value = None

# final return statement...
return value
3 changes: 0 additions & 3 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"name": "go-eCharger APIv2 Connect",
"country": [
"ALL"
],
"homeassistant": "2023.7.0",
"hacs": "1.18.0",
"render_readme": true
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
homeassistant>=2024.8.2
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest-homeassistant-custom-component>=0.13.154

0 comments on commit f5e1d0a

Please sign in to comment.