Skip to content

Commit

Permalink
fix #78 default on 16A but change value to 32 if there is license, fix
Browse files Browse the repository at this point in the history
…#77 lower comofort min value
  • Loading branch information
Tuen Lee committed Nov 3, 2023
1 parent e3eef36 commit 4cad244
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 19 deletions.
1 change: 1 addition & 0 deletions custom_components/alfen_wallbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b

await device.async_update()
device.get_number_of_socket()
device.get_licenses()

hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][config_entry.entry_id] = device
Expand Down
10 changes: 10 additions & 0 deletions custom_components/alfen_wallbox/alfen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
DOMAIN,
ALFEN_PRODUCT_MAP,
ID,
LICENSES,
METHOD_GET,
METHOD_POST,
OFFSET,
Expand Down Expand Up @@ -70,6 +71,7 @@ def __init__(self,
self.username = "admin"
self.password = password
self.properties = []
self.licenses = []
self._session.verify = False
self.keepLogout = False
self.wait = False
Expand Down Expand Up @@ -97,6 +99,14 @@ def get_number_of_socket(self):
self.number_socket = int(prop[VALUE])
break

def get_licenses(self):
for prop in self.properties:
if prop[ID] == '21A2_0':
for key, value in LICENSES.items():
if int(prop[VALUE]) & int(value):
self.licenses.append(key)
break

async def get_info(self):
response = await self._session.get(
url=self.__get_url(INFO), ssl=self.ssl
Expand Down
114 changes: 103 additions & 11 deletions custom_components/alfen_wallbox/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
from dataclasses import dataclass
from typing import Final

from .const import ID, VALUE
from .const import (
ID,
LICENSE_NONE,
LICENSE_SCN,
LICENSE_LOAD_BALANCING_STATIC,
LICENSE_LOAD_BALANCING_ACTIVE,
LICENSE_HIGH_POWER,
LICENSE_RFID,
LICENSE_PERSONALIZED_DISPLAY,
LICENSE_MOBILE,
LICENSE_PAYMENT_GIROE,
VALUE
)
from .alfen import AlfenDevice
from .entity import AlfenEntity

Expand All @@ -20,7 +32,6 @@
@dataclass
class AlfenBinaryDescriptionMixin:
"""Define an entity description mixin for binary sensor entities."""

api_param: str


Expand All @@ -36,6 +47,55 @@ class AlfenBinaryDescription(BinarySensorEntityDescription, AlfenBinaryDescripti
device_class=None,
api_param="205B_0",
),
AlfenBinaryDescription(
key="license_scn",
name="License Smart Charging Network",
device_class=None,
api_param=None,
),
AlfenBinaryDescription(
key="license_active_loadbalancing",
name="License Active Loadbalancing",
device_class=None,
api_param=None,
),
AlfenBinaryDescription(
key="license_static_loadbalancing",
name="License Static Loadbalancing",
device_class=None,
api_param=None,
),
AlfenBinaryDescription(
key="license_high_power_sockets",
name="License 32A Output per Socket",
device_class=None,
api_param=None,
),
AlfenBinaryDescription(
key="license_rfid_reader",
name="License RFID Reader",
device_class=None,
api_param=None,
),
AlfenBinaryDescription(
key="license_personalized_display",
name="License Personalized Display",
device_class=None,
api_param=None,
),
AlfenBinaryDescription(
key="license_mobile_3G_4G",
name="License Mobile 3G & 4G",
device_class=None,
api_param=None,
),
AlfenBinaryDescription(
key="license_giro_e",
name="License Giro-e Payment",
device_class=None,
api_param=None,
),

)


Expand Down Expand Up @@ -68,17 +128,49 @@ def __init__(self,
self._attr_unique_id = f"{self._device.id}_{description.key}"
self.entity_description = description

# custom code for license
if self.entity_description.api_param is None:
# check if license is available
if '21A2_0' in self._device.properties:
if self._device.properties['21A2_0'][VALUE] == LICENSE_NONE:
return False
if self.entity_description.key == "license_scn":
self._attr_is_on = LICENSE_SCN in self._device.licenses
if self.entity_description.key == "license_active_loadbalancing":
self._attr_is_on = LICENSE_SCN in self._device.licenses or LICENSE_LOAD_BALANCING_ACTIVE in self._device.licenses
if self.entity_description.key == "license_static_loadbalancing":
self._attr_is_on = LICENSE_SCN in self._device.licenses or LICENSE_LOAD_BALANCING_STATIC in self._device.licenses or LICENSE_LOAD_BALANCING_STATIC in self._device.licenses
if self.entity_description.key == "license_high_power_sockets":
self._attr_is_on = LICENSE_HIGH_POWER in self._device.licenses
if self.entity_description.key == "license_rfid_reader":
self._attr_is_on = LICENSE_RFID in self._device.licenses
if self.entity_description.key == "license_personalized_display":
self._attr_is_on = LICENSE_PERSONALIZED_DISPLAY in self._device.licenses
if self.entity_description.key == "license_mobile_3G_4G":
self._attr_is_on = LICENSE_MOBILE in self._device.licenses
if self.entity_description.key == "license_giro_e":
self._attr_is_on = LICENSE_PAYMENT_GIROE in self._device.licenses
# if self.entity_description.key == "license_qrcode":
# self._attr_is_on = LICENSE_PAYMENT_QRCODE in self._device.licenses
# if self.entity_description.key == "license_expose_smartmeterdata":
# self._attr_is_on = LICENSE_EXPOSE_SMARTMETERDATA in self._device.licenses

@property
def available(self) -> bool:
for prop in self._device.properties:
if prop[ID] == self.entity_description.api_param:
return True
return False
if self.entity_description.api_param is not None:
for prop in self._device.properties:
if prop[ID] == self.entity_description.api_param:
return True
return False
else:
return True

@property
def is_on(self) -> bool:
for prop in self._device.properties:
if prop[ID] == self.entity_description.api_param:
return prop[VALUE] == 1

return False
if self.entity_description.api_param is not None:
for prop in self._device.properties:
if prop[ID] == self.entity_description.api_param:
return prop[VALUE] == 1
return False
else:
return self._attr_is_on
32 changes: 30 additions & 2 deletions custom_components/alfen_wallbox/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
CAT_MBUS_TCP = "MbusTCP"
CAT_COMM = "comm"
CAT_DISPLAY = "display"
#CAT_LEDS = "leds"
#CAT_ACCELERO = "accelero"
# CAT_LEDS = "leds"
# CAT_ACCELERO = "accelero"
CAT_METER2 = "meter2"

COMMAND_REBOOT = "reboot"
Expand Down Expand Up @@ -98,3 +98,31 @@
"NG920-61215": "Eve Double Pro-line FR, 1 phase, Display, 2x socket Type 2S (shutters), max. 1x32A input current",
"NG920-61216": "Eve Double Pro-line FR, 1 phase, Display, 2x socket Type 2S (shutters), max. 2x32A input current",
}

LICENSE_NONE = "None"
LICENSE_SCN = "LoadBalancing_SCN"
LICENSE_LOAD_BALANCING_STATIC = "LoadBalancing_Static"
LICENSE_LOAD_BALANCING_ACTIVE = "LoadBalancing_Active"
LICENSE_HIGH_POWER = "HighPowerSockets"
LICENSE_RFID = "RFIDReader"
LICENSE_PERSONALIZED_DISPLAY = "PersonalizedDisplay"
LICENSE_MOBILE = "Mobile3G4G"
LICENSE_PAYMENT_GIROE = "Payment_GiroE"
LICENSE_PAYMENT_QRCODE = "Payment_QRCode"
LICENSE_EXPOSE_SMARTMETERDATA = "Expose_SmartMeterData"
LICENSE_OBJECTID = "ObjectID"

LICENSES = {
LICENSE_NONE: 0,
LICENSE_SCN: 1,
LICENSE_LOAD_BALANCING_STATIC: 2,
LICENSE_LOAD_BALANCING_ACTIVE: 4,
LICENSE_HIGH_POWER: 16,
LICENSE_RFID: 256,
LICENSE_PERSONALIZED_DISPLAY: 4096,
LICENSE_MOBILE: 65536,
LICENSE_PAYMENT_GIROE: 1048576,
LICENSE_PAYMENT_QRCODE: 131072,
LICENSE_EXPOSE_SMARTMETERDATA: 16777216,
LICENSE_OBJECTID: 2147483648
}
22 changes: 16 additions & 6 deletions custom_components/alfen_wallbox/number.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from homeassistant.helpers import entity_platform
from .const import ID, SERVICE_SET_COMFORT_POWER, SERVICE_SET_CURRENT_LIMIT, SERVICE_SET_GREEN_SHARE, VALUE
from .const import ID, LICENSE_HIGH_POWER, SERVICE_SET_COMFORT_POWER, SERVICE_SET_CURRENT_LIMIT, SERVICE_SET_GREEN_SHARE, VALUE
from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberEntityDescription, NumberMode
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -50,7 +50,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=1,
native_max_value=32,
native_max_value=16,
native_step=1,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
Expand All @@ -65,7 +65,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=0,
native_max_value=32,
native_max_value=16,
native_step=1,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
Expand All @@ -80,7 +80,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=0,
native_max_value=32,
native_max_value=16,
native_step=1,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
Expand All @@ -95,7 +95,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=0,
native_max_value=32,
native_max_value=16,
native_step=1,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
Expand Down Expand Up @@ -369,7 +369,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=0,
native_max_value=32,
native_max_value=16,
native_step=1,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
Expand Down Expand Up @@ -460,6 +460,16 @@ def __init__(
if description.native_step is not None:
self._attr_native_step = description.native_step

# override the amps and set them on 32A if there is a license for it
override_amps_api_key = [
'2068_0', '2129_0', '2062_0', '2067_0', '3129_0'
]
# check if device licenses has the high power socket license
if LICENSE_HIGH_POWER in self._device.licenses:
if description.api_param in override_amps_api_key:
self._attr_max_value = 32
self._attr_native_max_value = 32

@property
def native_value(self) -> float | None:
"""Return the entity value to represent the entity state."""
Expand Down

0 comments on commit 4cad244

Please sign in to comment.