Skip to content

Commit

Permalink
binary sensors for go-eController paired/connected
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Jan 10, 2025
1 parent 6d220d4 commit edf3ead
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 14 deletions.
5 changes: 2 additions & 3 deletions custom_components/goecharger_api2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from homeassistant.const import CONF_HOST, CONF_TYPE, CONF_ID, CONF_SCAN_INTERVAL, CONF_MODE, CONF_TOKEN
from homeassistant.core import HomeAssistant, Event, SupportsResponse
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as config_val, entity_registry as entity_reg, device_registry as device_reg
from homeassistant.helpers import config_validation as config_val, entity_registry as entity_reg, \
device_registry as device_reg
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import Entity, EntityDescription
from homeassistant.helpers.typing import UNDEFINED, UndefinedType
Expand Down Expand Up @@ -303,7 +304,6 @@ async def read_versions(self):
self._config_entry.data.get(CONF_HOST),
self._config_entry.title)},
"manufacturer": MANUFACTURER,
"suggested_area": "Garage",
"name": self._config_entry.title,
"model": self._config_entry.data.get(CONF_TYPE),
"sw_version": sw_version
Expand All @@ -319,7 +319,6 @@ async def read_versions(self):
self._config_entry.data.get(CONF_TOKEN),
self._config_entry.title)},
"manufacturer": MANUFACTURER,
"suggested_area": "Garage",
"name": self._config_entry.title,
"model": self._config_entry.data.get(CONF_TYPE),
"sw_version": self.bridge._versions[Tag.FWV.key]
Expand Down
13 changes: 9 additions & 4 deletions custom_components/goecharger_api2/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def is_on(self) -> bool | None:
value = None
if self.coordinator.data is not None:
if self.data_key in self.coordinator.data:
if self.entity_description.idx is not None:
if self.entity_description.tuple_idx is not None and len(self.entity_description.tuple_idx) > 1:
subKey1 = self.entity_description.tuple_idx[0]
subKey2 = self.entity_description.tuple_idx[1]
value = self.coordinator.data[self.data_key][subKey1][subKey2]
elif self.entity_description.idx is not None:
# hacking the CAR_CONNECT state... -> "car" > 1
if self.data_key == Tag.CAR_CONNECTED.key:
value = int(self.coordinator.data[self.data_key]) > 1
Expand All @@ -58,9 +62,10 @@ def is_on(self) -> bool | None:
value = None

except IndexError:
if self.entity_description.idx is not None:
_LOGGER.debug(
f"lc-key: {self.data_key.lower()} value: {value} idx: {self.entity_description.idx} -> {self.coordinator.data[self.data_key]}")
if self.entity_description.tuple_idx is not None:
_LOGGER.debug(f"lc-key: {self.data_key.lower()} value: {value} tuple_idx: {self.entity_description.tuple_idx} -> {self.coordinator.data[self.data_key]}")
elif self.entity_description.idx is not None:
_LOGGER.debug(f"lc-key: {self.data_key.lower()} value: {value} idx: {self.entity_description.idx} -> {self.coordinator.data[self.data_key]}")
else:
_LOGGER.debug(f"lc-key: {self.data_key.lower()} caused IndexError")
value = None
Expand Down
22 changes: 20 additions & 2 deletions custom_components/goecharger_api2/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from dataclasses import dataclass
from typing import Final

from custom_components.goecharger_api2.pygoecharger_ha.keys import Tag, IS_TRIGGER
Expand Down Expand Up @@ -38,6 +37,7 @@

class ExtBinarySensorEntityDescription(BinarySensorEntityDescription, frozen_or_thawed=True):
idx: int | None = None
tuple_idx: list | None = None
icon_off: str | None = None


Expand Down Expand Up @@ -164,7 +164,25 @@ class ExtSwitchEntityDescription(SwitchEntityDescription, frozen_or_thawed=True)
device_class=None,
icon="mdi:ab-testing",
entity_registry_enabled_default=False
)
),
ExtBinarySensorEntityDescription(
key=Tag.CTRLS.key,
translation_key="ctrls_0_paired", # important! 'translation_key' must be allways lower case!!!
tuple_idx=[0, 2],
entity_category=EntityCategory.DIAGNOSTIC,
device_class=None,
icon="mdi:gamepad-square-outline",
entity_registry_enabled_default=False
),
ExtBinarySensorEntityDescription(
key=Tag.CTRLS.key,
translation_key="ctrls_0_connected", # important! 'translation_key' must be allways lower case!!!
tuple_idx=[0, 3],
entity_category=EntityCategory.DIAGNOSTIC,
device_class=None,
icon="mdi:gamepad-square",
entity_registry_enabled_default=False
),
]
BUTTONS = [
ExtButtonEntityDescription(
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 @@ -11,5 +11,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-goecharger-api2/issues",
"requirements": [],
"version": "2024.12.1"
"version": "2025.0.1"
}
4 changes: 2 additions & 2 deletions custom_components/goecharger_api2/pygoecharger_ha/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# rbt: is the reboot time - and "looks like", that all other timestamps use the rbt "as" start point
FILTER_TIMES_ADDON: Final = ",rbt,fsptws,inva,lbp,lccfc,lccfi,lcctc,lfspt,lmsc,lpsc,lcs"

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"
FILTER_ALL_STATES: Final = "acu,adi,amt,atp,awcp,car,cards,cbl,ccu,ccw,cdi,cll,cus,ctrls,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"
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"

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"

# 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_COMON: Final = "aus,ccd,cle,clea,cmmr,cmp,cms,csa,ct,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"
Expand Down
3 changes: 3 additions & 0 deletions custom_components/goecharger_api2/pygoecharger_ha/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def __str__(self):
CUS = ApiKey(key="cus", cat=CAT.STATUS)
# cloud websocket enabled"
CWE = ApiKey(key="cwe", cat=CAT.CONFIG, writeable=True)
# information about a paired and connected go-eController
# [see https://github.com/marq24/ha-goecharger-api2/discussions/34]
CTRLS = ApiKey(key="ctrls", cat=CAT.STATUS)
# set this to 0-9 to clear card (erases card name, energy and rfid id)
DEL = ApiKey(key="del", cat=CAT.OTHER, writeable=True, writeonly=True)
# deltaA
Expand Down
4 changes: 3 additions & 1 deletion custom_components/goecharger_api2/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
"esk": {"name": "Gesetzte Lademenge kWh (Anzeige)"},
"fsp": {"name": "1-phasiges Laden erzwingen"},
"tlf": {"name": "Test-Ladung abgeschlossen"},
"tls": {"name": "Test-Ladung gestartet"}
"tls": {"name": "Test-Ladung gestartet"},
"ctrls_0_paired": {"name": "go-eController gepaart"},
"ctrls_0_connected": {"name": "go-eController verbunden"}
},
"button": {
"rst": {"name": "go-e Neustarten"},
Expand Down
4 changes: 3 additions & 1 deletion custom_components/goecharger_api2/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
"esk": {"name": "energy set kwh (only stored for app)"},
"fsp": {"name": "Force single phase"},
"tlf": {"name": "Test charging finished"},
"tls": {"name": "Test charging started"}
"tls": {"name": "Test charging started"},
"ctrls_0_paired": {"name": "go-eController paired"},
"ctrls_0_connected": {"name": "go-eController connected"}
},
"button": {
"rst": {"name": "Restart go-e device"},
Expand Down

0 comments on commit edf3ead

Please sign in to comment.