Skip to content

Commit 43faff4

Browse files
author
marq24
committed
support for energy per card #28
1 parent b344b45 commit 43faff4

File tree

7 files changed

+200
-31
lines changed

7 files changed

+200
-31
lines changed

custom_components/goecharger_api2/const.py

Lines changed: 139 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,35 @@
3636
WAN: Final = "wan"
3737
LAN: Final = "lan"
3838

39-
@dataclass
40-
class ExtBinarySensorEntityDescription(BinarySensorEntityDescription):
39+
class ExtBinarySensorEntityDescription(BinarySensorEntityDescription, frozen_or_thawed=True):
4140
idx: int | None = None
4241
icon_off: str | None = None
4342

4443

45-
@dataclass
46-
class ExtButtonEntityDescription(ButtonEntityDescription):
44+
class ExtButtonEntityDescription(ButtonEntityDescription, frozen_or_thawed=True):
4745
payload: str | None = None
4846

4947

50-
@dataclass
51-
class ExtNumberEntityDescription(NumberEntityDescription):
48+
class ExtNumberEntityDescription(NumberEntityDescription, frozen_or_thawed=True):
5249
write_zero_as_null: bool | None = None
5350
handle_as_float: bool | None = None
5451
factor: int | None = None
5552
idx: int | str | None = None
5653
check_16a_limit: bool | None = None
5754

58-
@dataclass
59-
class ExtSelectEntityDescription(SelectEntityDescription):
55+
class ExtSelectEntityDescription(SelectEntityDescription, frozen_or_thawed=True):
6056
idx: int | str | None = None
6157

6258

63-
@dataclass
64-
class ExtSensorEntityDescription(SensorEntityDescription):
59+
class ExtSensorEntityDescription(SensorEntityDescription, frozen_or_thawed=True):
6560
idx: int | str | None = None
6661
tuple_idx: list | None = None
6762
factor: int | None = None
6863
lookup: bool | None = None
6964
differential_base_key: str | None = None
7065

7166

72-
@dataclass
73-
class ExtSwitchEntityDescription(SwitchEntityDescription):
67+
class ExtSwitchEntityDescription(SwitchEntityDescription, frozen_or_thawed=True):
7468
is_zero_or_one: bool | None = None
7569
icon_off: str | None = None
7670
idx: int | str | None = None
@@ -1681,7 +1675,140 @@ class ExtSwitchEntityDescription(SwitchEntityDescription):
16811675
# wsc -> later (if at all)
16821676
# wsm -> later (if at all)
16831677

1678+
ExtSensorEntityDescription(
1679+
key=Tag.CARDS.key,
1680+
tuple_idx=[0, "energy"],
1681+
entity_category=EntityCategory.DIAGNOSTIC,
1682+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1683+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1684+
suggested_display_precision=2,
1685+
state_class=SensorStateClass.TOTAL_INCREASING,
1686+
icon="mdi:lightning-bolt",
1687+
device_class=SensorDeviceClass.ENERGY,
1688+
entity_registry_enabled_default=True
1689+
),
1690+
ExtSensorEntityDescription(
1691+
key=Tag.CARDS.key,
1692+
tuple_idx=[1, "energy"],
1693+
entity_category=EntityCategory.DIAGNOSTIC,
1694+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1695+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1696+
suggested_display_precision=2,
1697+
state_class=SensorStateClass.TOTAL_INCREASING,
1698+
icon="mdi:lightning-bolt",
1699+
device_class=SensorDeviceClass.ENERGY,
1700+
entity_registry_enabled_default=False
1701+
),
1702+
ExtSensorEntityDescription(
1703+
key=Tag.CARDS.key,
1704+
tuple_idx=[2, "energy"],
1705+
entity_category=EntityCategory.DIAGNOSTIC,
1706+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1707+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1708+
suggested_display_precision=2,
1709+
state_class=SensorStateClass.TOTAL_INCREASING,
1710+
icon="mdi:lightning-bolt",
1711+
device_class=SensorDeviceClass.ENERGY,
1712+
entity_registry_enabled_default=False
1713+
),
1714+
ExtSensorEntityDescription(
1715+
key=Tag.CARDS.key,
1716+
tuple_idx=[3, "energy"],
1717+
entity_category=EntityCategory.DIAGNOSTIC,
1718+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1719+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1720+
suggested_display_precision=2,
1721+
state_class=SensorStateClass.TOTAL_INCREASING,
1722+
icon="mdi:lightning-bolt",
1723+
device_class=SensorDeviceClass.ENERGY,
1724+
entity_registry_enabled_default=False
1725+
),
1726+
ExtSensorEntityDescription(
1727+
key=Tag.CARDS.key,
1728+
tuple_idx=[4, "energy"],
1729+
entity_category=EntityCategory.DIAGNOSTIC,
1730+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1731+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1732+
suggested_display_precision=2,
1733+
state_class=SensorStateClass.TOTAL_INCREASING,
1734+
icon="mdi:lightning-bolt",
1735+
device_class=SensorDeviceClass.ENERGY,
1736+
entity_registry_enabled_default=False
1737+
),
1738+
ExtSensorEntityDescription(
1739+
key=Tag.CARDS.key,
1740+
tuple_idx=[5, "energy"],
1741+
entity_category=EntityCategory.DIAGNOSTIC,
1742+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1743+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1744+
suggested_display_precision=2,
1745+
state_class=SensorStateClass.TOTAL_INCREASING,
1746+
icon="mdi:lightning-bolt",
1747+
device_class=SensorDeviceClass.ENERGY,
1748+
entity_registry_enabled_default=False
1749+
),
1750+
ExtSensorEntityDescription(
1751+
key=Tag.CARDS.key,
1752+
tuple_idx=[6, "energy"],
1753+
entity_category=EntityCategory.DIAGNOSTIC,
1754+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1755+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1756+
suggested_display_precision=2,
1757+
state_class=SensorStateClass.TOTAL_INCREASING,
1758+
icon="mdi:lightning-bolt",
1759+
device_class=SensorDeviceClass.ENERGY,
1760+
entity_registry_enabled_default=False
1761+
),
1762+
ExtSensorEntityDescription(
1763+
key=Tag.CARDS.key,
1764+
tuple_idx=[7, "energy"],
1765+
entity_category=EntityCategory.DIAGNOSTIC,
1766+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1767+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1768+
suggested_display_precision=2,
1769+
state_class=SensorStateClass.TOTAL_INCREASING,
1770+
icon="mdi:lightning-bolt",
1771+
device_class=SensorDeviceClass.ENERGY,
1772+
entity_registry_enabled_default=False
1773+
),
1774+
ExtSensorEntityDescription(
1775+
key=Tag.CARDS.key,
1776+
tuple_idx=[8, "energy"],
1777+
entity_category=EntityCategory.DIAGNOSTIC,
1778+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1779+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1780+
suggested_display_precision=2,
1781+
state_class=SensorStateClass.TOTAL_INCREASING,
1782+
icon="mdi:lightning-bolt",
1783+
device_class=SensorDeviceClass.ENERGY,
1784+
entity_registry_enabled_default=False
1785+
),
1786+
ExtSensorEntityDescription(
1787+
key=Tag.CARDS.key,
1788+
tuple_idx=[9, "energy"],
1789+
entity_category=EntityCategory.DIAGNOSTIC,
1790+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1791+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1792+
suggested_display_precision=2,
1793+
state_class=SensorStateClass.TOTAL_INCREASING,
1794+
icon="mdi:lightning-bolt",
1795+
device_class=SensorDeviceClass.ENERGY,
1796+
entity_registry_enabled_default=False
1797+
),
1798+
ExtSensorEntityDescription(
1799+
key=Tag.CARDS.key,
1800+
tuple_idx=[10, "energy"],
1801+
entity_category=EntityCategory.DIAGNOSTIC,
1802+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
1803+
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
1804+
suggested_display_precision=2,
1805+
state_class=SensorStateClass.TOTAL_INCREASING,
1806+
icon="mdi:lightning-bolt",
1807+
device_class=SensorDeviceClass.ENERGY,
1808+
entity_registry_enabled_default=False
1809+
),
16841810
]
1811+
16851812
SWITCH_SENSORS = [
16861813
ExtSwitchEntityDescription(
16871814
key=Tag.ACP.key,

custom_components/goecharger_api2/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"iot_class": "local_polling",
1212
"issue_tracker": "https://github.com/marq24/ha-goecharger-api2/issues",
1313
"requirements": [],
14-
"version": "2024.11.0"
14+
"version": "2024.11.1"
1515
}

custom_components/goecharger_api2/pygoecharger_ha/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ async def read_all_states(self):
145145

146146
async def force_config_update(self):
147147
self._LAST_CONFIG_UPDATE_TS = 0
148+
self._LAST_FULL_STATE_UPDATE_TS = 0
148149
await self.read_all_config()
149150

150151
async def read_all_config(self):

custom_components/goecharger_api2/pygoecharger_ha/const.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# rbt: is the reboot time - and "looks like", that all other timestamps use the rbt "as" start point
1313
FILTER_TIMES_ADDON: Final = ",rbt,fsptws,inva,lbp,lccfc,lccfi,lcctc,lfspt,lmsc,lpsc,lcs"
1414

15-
FILTER_ALL_STATES: Final = "acu,adi,amt,atp,awcp,car,cbl,ccu,ccw,cdi,cll,cus,deltaa,deltap,err,eto,ffb,fhz,fsp,fsptws,inva,lbp,lccfc,lccfi,lcctc,lck,lfspt,lmsc,loa,lpsc,mcpea,mmp,modelStatus,nif,nrg,pakku,pgrid,pha,pnp,ppv,pvopt_averagePAkku,pvopt_averagePGrid,pvopt_averagePPv,pwm,rbc,rbt,rfb,rssi,rst,tlf,tls,tma,tpa,trx,wh,wsms,wst"
16-
FILTER_ALL_CONFIG: Final = "acp,acs,ama,amp,ara,ate,att,awc,awe,awp,bac,cch,cco,cfi,cid,clp,cmse,cwc,cwe,dwo,esk,fmt,fna,frc,frm,fst,fup,fzf,hsa,lbr,lmo,loe,lof,log,lop,lot,loty,lse,map,mca,mci,mcpd,mptwt,mpwst,nmo,pgt,po,psh,psm,psmd,rdbf,rdbs,rdef,rdes,rdre,rdpl,sch_satur,sch_sund,sch_week,sdp,sh,spl3,su,sua,sumd,tds,tof,upo,ust,zfo"
15+
FILTER_ALL_STATES: Final = "acu,adi,amt,atp,awcp,car,cards,cbl,ccu,ccw,cdi,cll,cus,deltaa,deltap,err,eto,ffb,fhz,fsp,fsptws,inva,lbp,lccfc,lccfi,lcctc,lck,lfspt,lmsc,loa,lpsc,mcpea,mmp,modelStatus,nif,nrg,pakku,pgrid,pha,pnp,ppv,pvopt_averagePAkku,pvopt_averagePGrid,pvopt_averagePPv,pwm,rbc,rbt,rfb,rssi,rst,tlf,tls,tma,tpa,trx,wh,wsms,wst"
16+
FILTER_ALL_CONFIG: Final = "acp,acs,ama,amp,ara,ate,att,awc,awe,awp,bac,cards,cch,cco,cfi,cid,clp,cmse,cwc,cwe,dwo,esk,fmt,fna,frc,frm,fst,fup,fzf,hsa,lbr,lmo,loe,lof,log,lop,lot,loty,lse,map,mca,mci,mcpd,mptwt,mpwst,nmo,pgt,po,psh,psm,psmd,rdbf,rdbs,rdef,rdes,rdre,rdpl,sch_satur,sch_sund,sch_week,sdp,sh,spl3,su,sua,sumd,tds,tof,upo,ust,zfo"
1717

1818
FILTER_NOT_USED: Final = "mcc,mcca,mce,mcr,mcs,mcu,men,mlr,mlra,mqcn,mqg,mqss,msb,msp,msr,mtp,ocppai,ocppi,rdbfe,rdbse,rdefe,rdese,rdree,rdple"
1919

custom_components/goecharger_api2/select.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,25 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, add_
3232
class GoeChargerSelect(GoeChargerBaseEntity, SelectEntity):
3333
def __init__(self, coordinator: GoeChargerDataUpdateCoordinator, description: ExtSelectEntityDescription):
3434
if description.key == Tag.TRX.key:
35-
options = ["null", "0"]
36-
description.options = options + coordinator.available_cards_idx
35+
new_options = ["null", "0"] + coordinator.available_cards_idx
36+
# ok we need to create a new entity description with the new options...
37+
# [since ExtSelectEntityDescription is frozen]
38+
description = ExtSelectEntityDescription (
39+
key = description.key,
40+
device_class = description.device_class,
41+
entity_category = description.entity_category,
42+
entity_registry_enabled_default = description.entity_registry_enabled_default,
43+
entity_registry_visible_default = description.entity_registry_visible_default,
44+
force_update = description.force_update,
45+
icon = description.icon,
46+
has_entity_name = description.has_entity_name,
47+
name = description.name,
48+
translation_key = description.translation_key,
49+
translation_placeholders = description.translation_placeholders,
50+
unit_of_measurement = description.unit_of_measurement,
51+
options = new_options,
52+
idx = description.idx,
53+
)
3754
super().__init__(coordinator=coordinator, description=description)
3855

3956
@property

custom_components/goecharger_api2/translations/de.json

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"esk": {"name": "Gesetzte Lademenge kWh (Anzeige)"},
9595
"fsp": {"name": "1-phasiges Laden erzwingen"},
9696
"tlf": {"name": "Test-Ladung abgeschlossen"},
97-
"tls": {"name": "Test-Ladung gestartet"}
97+
"tls": {"name": "Test-Ladung gestartet"}
9898
},
9999
"button": {
100100
"rst": {"name": "go-e Neustarten"},
@@ -384,23 +384,23 @@
384384

385385
"isv_0_i": {"name": "Strom Internal 1"},
386386
"isv_0_p": {"name": "Leistung Internal 1"},
387-
"isv_0_f": {"name": "Leistungsfaktor Internal 1"},
387+
"isv_0_f": {"name": "Leistungsfaktor Internal 1"},
388388
"isv_1_i": {"name": "Strom Internal 2"},
389389
"isv_1_p": {"name": "Leistung Internal 2"},
390-
"isv_1_f": {"name": "Leistungsfaktor Internal 2"},
390+
"isv_1_f": {"name": "Leistungsfaktor Internal 2"},
391391
"isv_2_i": {"name": "Strom Internal 3"},
392392
"isv_2_p": {"name": "Leistung Internal 3"},
393-
"isv_2_f": {"name": "Leistungsfaktor Internal 3"},
393+
"isv_2_f": {"name": "Leistungsfaktor Internal 3"},
394394
"isv_3_i": {"name": "Strom Internal 4"},
395395
"isv_3_p": {"name": "Leistung Internal 4"},
396-
"isv_3_f": {"name": "Leistungsfaktor Internal 4"},
396+
"isv_3_f": {"name": "Leistungsfaktor Internal 4"},
397397
"isv_4_i": {"name": "Strom Internal 5"},
398398
"isv_4_p": {"name": "Leistung Internal 5"},
399-
"isv_4_f": {"name": "Leistungsfaktor Internal 5"},
399+
"isv_4_f": {"name": "Leistungsfaktor Internal 5"},
400400
"isv_5_i": {"name": "Strom Internal 6"},
401401
"isv_5_p": {"name": "Leistung Internal 6"},
402402
"isv_5_f": {"name": "Leistungsfaktor Internal 6"},
403-
403+
404404
"cec_0_0": {"name": "Kategorie 1 Zähler Verbrauch"},
405405
"cec_0_1": {"name": "Kategorie 1 Zähler Überschuss"},
406406
"cec_1_0": {"name": "Kategorie 2 Zähler Verbrauch"},
@@ -452,7 +452,19 @@
452452
"ccp_15": {"name": "Kategorie 16 Leistung"},
453453

454454
"mecu": {"name": "MEC Meter Url"},
455-
"mmh": {"name": "Modbus Master Host"}
455+
"mmh": {"name": "Modbus Master Host"},
456+
457+
"cards_0_energy": {"name": "Lademenge Karte"},
458+
"cards_1_energy": {"name": "Lademenge Karte 1"},
459+
"cards_2_energy": {"name": "Lademenge Karte 2"},
460+
"cards_3_energy": {"name": "Lademenge Karte 3"},
461+
"cards_4_energy": {"name": "Lademenge Karte 4"},
462+
"cards_5_energy": {"name": "Lademenge Karte 5"},
463+
"cards_6_energy": {"name": "Lademenge Karte 6"},
464+
"cards_7_energy": {"name": "Lademenge Karte 7"},
465+
"cards_8_energy": {"name": "Lademenge Karte 8"},
466+
"cards_9_energy": {"name": "Lademenge Karte 9"},
467+
"cards_10_energy": {"name": "Lademenge Karte 10"}
456468
},
457469
"switch": {
458470
"acp": {"name": "Ladepausen zulassen (Fahrzeug Kompatibilität)"},

custom_components/goecharger_api2/translations/en.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"esk": {"name": "energy set kwh (only stored for app)"},
9595
"fsp": {"name": "Force single phase"},
9696
"tlf": {"name": "Test charging finished"},
97-
"tls": {"name": "Test charging started"}
97+
"tls": {"name": "Test charging started"}
9898
},
9999
"button": {
100100
"rst": {"name": "Restart go-e device"},
@@ -387,16 +387,16 @@
387387
"isv_0_f": {"name": "Power factor Internal 1"},
388388
"isv_1_i": {"name": "Ampere Internal 2"},
389389
"isv_1_p": {"name": "Power Internal 2"},
390-
"isv_1_f": {"name": "Power factor Internal 2"},
390+
"isv_1_f": {"name": "Power factor Internal 2"},
391391
"isv_2_i": {"name": "Ampere Internal 3"},
392392
"isv_2_p": {"name": "Power Internal 3"},
393-
"isv_2_f": {"name": "Power factor Internal 3"},
393+
"isv_2_f": {"name": "Power factor Internal 3"},
394394
"isv_3_i": {"name": "Ampere Internal 4"},
395395
"isv_3_p": {"name": "Power Internal 4"},
396-
"isv_3_f": {"name": "Power factor Internal 4"},
396+
"isv_3_f": {"name": "Power factor Internal 4"},
397397
"isv_4_i": {"name": "Ampere Internal 5"},
398398
"isv_4_p": {"name": "Power Internal 5"},
399-
"isv_4_f": {"name": "Power factor Internal 5"},
399+
"isv_4_f": {"name": "Power factor Internal 5"},
400400
"isv_5_i": {"name": "Ampere Internal 6"},
401401
"isv_5_p": {"name": "Power Internal 6"},
402402
"isv_5_f": {"name": "Power factor Internal 6"},
@@ -452,7 +452,19 @@
452452
"ccp_15": {"name": "Category 16 Power"},
453453

454454
"mecu": {"name": "MEC meter url"},
455-
"mmh": {"name": "Modbus master host"}
455+
"mmh": {"name": "Modbus master host"},
456+
457+
"cards_0_energy": {"name": "Energy Card"},
458+
"cards_1_energy": {"name": "Energy Card 1"},
459+
"cards_2_energy": {"name": "Energy Card 2"},
460+
"cards_3_energy": {"name": "Energy Card 3"},
461+
"cards_4_energy": {"name": "Energy Card 4"},
462+
"cards_5_energy": {"name": "Energy Card 5"},
463+
"cards_6_energy": {"name": "Energy Card 6"},
464+
"cards_7_energy": {"name": "Energy Card 7"},
465+
"cards_8_energy": {"name": "Energy Card 8"},
466+
"cards_9_energy": {"name": "Energy Card 9"},
467+
"cards_10_energy": {"name": "Energy Card 10"}
456468
},
457469
"switch": {
458470
"acp": {"name": "Allow Charge Pause (car compatibility)"},

0 commit comments

Comments
 (0)