Skip to content

Commit

Permalink
Merge pull request #24 from leeyuentuen/dev
Browse files Browse the repository at this point in the history
Dev to master
  • Loading branch information
leeyuentuen authored Jul 21, 2023
2 parents 7116a1d + 816092a commit a069707
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
2 changes: 1 addition & 1 deletion custom_components/alfen_wallbox/alfen.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async def _do_update(self):
offset += len(response_json[PROPERTIES])

await self.logout()

_LOGGER.debug(f"Properties {properties}")
self.properties = properties

async def async_get_info(self):
Expand Down
34 changes: 19 additions & 15 deletions custom_components/alfen_wallbox/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import DOMAIN as ALFEN_DOMAIN
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import HomeAssistant
import logging
from typing import Final, Any
from typing import Final
from dataclasses import dataclass
from .entity import AlfenEntity
from .alfen import AlfenDevice
Expand All @@ -25,6 +25,7 @@ class AlfenNumberDescriptionMixin:
assumed_state: bool
state: float
api_param: str
custom_mode: str


@dataclass
Expand All @@ -41,9 +42,9 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=1,
native_max_value=16,
native_max_value=32,
native_step=1,
mode=NumberMode.SLIDER,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
api_param="2068_0",
),
Expand All @@ -55,9 +56,9 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=0,
native_max_value=16,
native_max_value=32,
native_step=1,
mode=NumberMode.SLIDER,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
api_param="2129_0",
),
Expand All @@ -69,9 +70,9 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=0,
native_max_value=16,
native_max_value=32,
native_step=1,
mode=NumberMode.SLIDER,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
api_param="2062_0",
),
Expand All @@ -83,9 +84,9 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
assumed_state=False,
device_class=NumberDeviceClass.CURRENT,
native_min_value=0,
native_max_value=16,
native_max_value=32,
native_step=1,
mode=NumberMode.SLIDER,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
api_param="2067_0",
),
Expand All @@ -99,7 +100,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
native_min_value=0,
native_max_value=100,
native_step=1,
mode=NumberMode.SLIDER,
custom_mode=None,
unit_of_measurement=PERCENTAGE,
api_param="3280_2",
),
Expand All @@ -113,7 +114,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
native_min_value=1400,
native_max_value=3500,
native_step=100,
mode=NumberMode.SLIDER,
custom_mode=None,
unit_of_measurement=UnitOfPower.WATT,
api_param="3280_3",
),
Expand All @@ -127,7 +128,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
native_min_value=0,
native_max_value=100,
native_step=10,
mode=NumberMode.SLIDER,
custom_mode=None,
unit_of_measurement=PERCENTAGE,
api_param="2061_2",
),
Expand All @@ -141,7 +142,7 @@ class AlfenNumberDescription(NumberEntityDescription, AlfenNumberDescriptionMixi
native_min_value=0,
native_max_value=10,
native_step=1,
mode=NumberMode.SLIDER,
custom_mode=None,
unit_of_measurement=UnitOfElectricCurrent.AMPERE,
api_param="2174_0",
),
Expand Down Expand Up @@ -179,7 +180,10 @@ def __init__(
self._attr_assumed_state = description.assumed_state
self._attr_device_class = description.device_class
self._attr_icon = description.icon
self._attr_mode = description.mode
if description.custom_mode is None: # issue with pre Home Assistant Core 2023.6 versions
self._attr_mode = NumberMode.SLIDER
else:
self._attr_mode = description.custom_mode
self._attr_native_unit_of_measurement = description.unit_of_measurement
self._attr_native_value = description.state
self.entity_description = description
Expand Down
2 changes: 2 additions & 0 deletions custom_components/alfen_wallbox/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class AlfenSelectDescription(SelectEntityDescription, AlfenSelectDescriptionMixi
"Portuguese": "pt_PT",
"Spanish": "es_ES",
"Swedish": "sv_SE",
"Polish": "pl_PL",
"Danish": "da_DK",
}

ALLOWED_PHASE_DICT: Final[dict[str, int]] = {
Expand Down
31 changes: 27 additions & 4 deletions custom_components/alfen_wallbox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AlfenSensorDescription(
10: "Vehicle connected",
11: "Charging Active Normal",
12: "Charging Active Simplified",
13: "Charging Suyspended Over Current",
13: "Charging Suspended Over Current",
14: "Charging Suspended HF Switching",
15: "Charging Suspended EV Disconnected",
16: "Finish Wait Vehicle",
Expand Down Expand Up @@ -231,15 +231,15 @@ class AlfenSensorDescription(

AlfenSensorDescription(
key="main_static_lb_max_current",
name="Main Static Load Balancing Max Current",
name="Main Static LB Max Current",
icon="mdi:current-ac",
api_param="212B_0",
unit=UnitOfElectricCurrent.AMPERE,
round_digits=2,
),
AlfenSensorDescription(
key="main_active_lb_max_current",
name="Main Active Load Balancing Max Current",
name="Main Active LB Max Current",
icon="mdi:current-ac",
api_param="212D_0",
unit=UnitOfElectricCurrent.AMPERE,
Expand Down Expand Up @@ -544,12 +544,28 @@ class AlfenSensorDescription(
),
AlfenSensorDescription(
key="lb_max_allowed_phase_socket_1",
name="Load Balancing Max Allowed of Phases Socket 1",
name="LB Max Allowed of Phases Socket 1",
icon="mdi:scale-balance",
unit=None,
api_param="312E_0",
round_digits=None,
),
AlfenSensorDescription(
key="ui_state_1",
name="Display State Socket 1",
icon="mdi:information-outline",
unit=None,
api_param="3190_1",
round_digits=None,
),
AlfenSensorDescription(
key="ui_error_number",
name="Display Error Number Socket 1",
icon="mdi:information-outline",
unit=None,
api_param="3190_2",
round_digits=None,
),
# 2 Socket devices
# AlfenSensorDescription(
# key="lb_max_allowed_phase_socket_2",
Expand Down Expand Up @@ -804,6 +820,13 @@ def state(self) -> StateType:
if prop[ID] == self.entity_description.api_param:
# some exception of return value

# Display state status
if self.entity_description.api_param == "3190_1":
if prop[VALUE] == 28:
return "See error Number"
else:
return STATUS_DICT.get(prop[VALUE], 'Unknown')

# meter_reading from w to kWh
if self.entity_description.api_param == "2221_22":
return round((prop[VALUE] / 1000), 2)
Expand Down

0 comments on commit a069707

Please sign in to comment.