From 241ddd5d6fb5bb7a5cb62fccaa48059c1d9767cb Mon Sep 17 00:00:00 2001 From: bullitt168 Date: Tue, 23 Jul 2024 17:27:28 +0000 Subject: [PATCH 1/2] Fixed Wallbox Lambda Functions in Button & Switch, Renamed Button Entities to include "Toggle" --- custom_components/e3dc_rscp/button.py | 4 ++-- custom_components/e3dc_rscp/strings.json | 4 ++-- custom_components/e3dc_rscp/switch.py | 16 ++++------------ custom_components/e3dc_rscp/translations/en.json | 4 ++-- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/custom_components/e3dc_rscp/button.py b/custom_components/e3dc_rscp/button.py index db62681..97fc15b 100644 --- a/custom_components/e3dc_rscp/button.py +++ b/custom_components/e3dc_rscp/button.py @@ -55,7 +55,7 @@ async def async_setup_entry( key=f"{wallbox_key}-toggle-wallbox-phases", translation_key="wallbox-toggle-wallbox-phases", icon="mdi:sine-wave", - async_press_action=lambda coordinator: coordinator.async_toggle_wallbox_phases(wallbox["index"]), + async_press_action=lambda coordinator, index=wallbox["index"]: coordinator.async_toggle_wallbox_phases(index), ) entities.append(E3DCButton(coordinator, wallbox_toggle_wallbox_phases_description, unique_id, wallbox["deviceInfo"])) @@ -63,7 +63,7 @@ async def async_setup_entry( key=f"{wallbox_key}-toggle-wallbox-charging", translation_key="wallbox-toggle-wallbox-charging", icon="mdi:car-electric", - async_press_action=lambda coordinator: coordinator.async_toggle_wallbox_charging(wallbox["index"]), + async_press_action=lambda coordinator, index=wallbox["index"]: coordinator.async_toggle_wallbox_charging(index), ) entities.append(E3DCButton(coordinator, wallbox_toggle_wallbox_charging_description, unique_id, wallbox["deviceInfo"])) diff --git a/custom_components/e3dc_rscp/strings.json b/custom_components/e3dc_rscp/strings.json index 3c8a692..2a292c1 100644 --- a/custom_components/e3dc_rscp/strings.json +++ b/custom_components/e3dc_rscp/strings.json @@ -265,10 +265,10 @@ }, "button": { "wallbox-toggle-wallbox-charging": { - "name": "Charging" + "name": "Toggle charging" }, "wallbox-toggle-wallbox-phases": { - "name": "Phases" + "name": "Toggle phases" } }, "number": { diff --git a/custom_components/e3dc_rscp/switch.py b/custom_components/e3dc_rscp/switch.py index 5bd7717..5fb71ec 100644 --- a/custom_components/e3dc_rscp/switch.py +++ b/custom_components/e3dc_rscp/switch.py @@ -94,12 +94,8 @@ async def async_setup_entry( on_icon="mdi:weather-sunny", off_icon="mdi:weather-sunny-off", device_class=SwitchDeviceClass.SWITCH, - async_turn_on_action=lambda coordinator: coordinator.async_set_wallbox_sun_mode( - True, wallbox["index"] - ), - async_turn_off_action=lambda coordinator: coordinator.async_set_wallbox_sun_mode( - False, wallbox["index"] - ), + async_turn_on_action=lambda coordinator, index=wallbox["index"]: coordinator.async_set_wallbox_sun_mode(True, index), + async_turn_off_action=lambda coordinator, index=wallbox["index"]: coordinator.async_set_wallbox_sun_mode(False, index), ) entities.append(E3DCSwitch(coordinator, wallbox_sun_mode_description, unique_id, wallbox["deviceInfo"])) @@ -110,12 +106,8 @@ async def async_setup_entry( on_icon="mdi:power-plug", off_icon="mdi:power-plug-off", device_class=SwitchDeviceClass.OUTLET, - async_turn_on_action=lambda coordinator: coordinator.async_set_wallbox_schuko( - True, wallbox["index"] - ), - async_turn_off_action=lambda coordinator: coordinator.async_set_wallbox_schuko( - False, wallbox["index"] - ), + async_turn_on_action=lambda coordinator, index=wallbox["index"]: coordinator.async_set_wallbox_schuko(True, index), + async_turn_off_action=lambda coordinator, index=wallbox["index"]: coordinator.async_set_wallbox_schuko(False, index), entity_registry_enabled_default=False, # Disabled per default as only Wallbox multi connect I provides this feature ) entities.append(E3DCSwitch(coordinator, wallbox_schuko_description, unique_id, wallbox["deviceInfo"])) diff --git a/custom_components/e3dc_rscp/translations/en.json b/custom_components/e3dc_rscp/translations/en.json index 263b07e..0212667 100644 --- a/custom_components/e3dc_rscp/translations/en.json +++ b/custom_components/e3dc_rscp/translations/en.json @@ -265,10 +265,10 @@ }, "button": { "wallbox-toggle-wallbox-charging": { - "name": "Charging" + "name": "Toggle charging" }, "wallbox-toggle-wallbox-phases": { - "name": "Phases" + "name": "Toggle phases" } }, "number": { From becd9c653599e4a18379978c05df69755c2c5376 Mon Sep 17 00:00:00 2001 From: bullitt168 Date: Mon, 29 Jul 2024 19:32:37 +0000 Subject: [PATCH 2/2] Made Sensor Wallbox Consumption only available if Wallbox is installed --- custom_components/e3dc_rscp/sensor.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/custom_components/e3dc_rscp/sensor.py b/custom_components/e3dc_rscp/sensor.py index 0733aed..c029318 100644 --- a/custom_components/e3dc_rscp/sensor.py +++ b/custom_components/e3dc_rscp/sensor.py @@ -184,17 +184,6 @@ device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), - SensorEntityDescription( - key="wallbox-consumption", - translation_key="wallbox-consumption", - icon="mdi:ev-station", - native_unit_of_measurement=UnitOfPower.WATT, - suggested_unit_of_measurement=UnitOfPower.KILO_WATT, - suggested_display_precision=2, - device_class=SensorDeviceClass.POWER, - state_class=SensorStateClass.MEASUREMENT, - entity_registry_enabled_default=False, - ), SensorEntityDescription( key="grid-netchange", translation_key="grid-netchange", @@ -532,6 +521,18 @@ async def async_setup_entry( ) entities.append(E3DCSensor(coordinator, wallbox_soc_description, unique_id, wallbox["deviceInfo"])) + if len(coordinator.wallboxes) > 0: + wallbox_consumption_description = SensorEntityDescription( + key="wallbox-consumption", + translation_key="wallbox-consumption", + icon="mdi:ev-station", + native_unit_of_measurement=UnitOfPower.WATT, + suggested_unit_of_measurement=UnitOfPower.KILO_WATT, + suggested_display_precision=2, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, + ) + entities.append(E3DCSensor(coordinator, wallbox_consumption_description, entry.unique_id)) async_add_entities(entities)