Skip to content

Commit

Permalink
Add "force smart charging" option to configuration flow (#612)
Browse files Browse the repository at this point in the history
* Add "force smart charging" option to configuration flow

Add "force smart charging" option to configuration flow

* fix linting

* update tests

* alt test logic

* fix ref

* update config entry

* set mock entry to true

* remove assert

Co-authored-by: drc38 <derek_Caudwell@hotmail.com>
  • Loading branch information
birneee and drc38 authored Sep 10, 2022
1 parent 2dfca3a commit 9b6ce56
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 19 deletions.
9 changes: 8 additions & 1 deletion custom_components/ocpp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
CONF_CPID,
CONF_CSID,
CONF_DEFAULT_AUTH_STATUS,
CONF_FORCE_SMART_CHARGING,
CONF_HOST,
CONF_ID_TAG,
CONF_IDLE_INTERVAL,
Expand All @@ -72,6 +73,7 @@
DEFAULT_CPID,
DEFAULT_CSID,
DEFAULT_ENERGY_UNIT,
DEFAULT_FORCE_SMART_CHARGING,
DEFAULT_HOST,
DEFAULT_IDLE_INTERVAL,
DEFAULT_MEASURAND,
Expand Down Expand Up @@ -486,6 +488,11 @@ async def get_supported_features(self):
_LOGGER.warning("No feature profiles detected, defaulting to Core")
await self.notify_ha("No feature profiles detected, defaulting to Core")
feature_list = [om.feature_profile_core.value]
if self.central.config.get(
CONF_FORCE_SMART_CHARGING, DEFAULT_FORCE_SMART_CHARGING
):
_LOGGER.warning("Force Smart Charging feature profile")
self._attr_supported_features |= prof.SMART
for item in feature_list:
item = item.strip()
if item == om.feature_profile_core.value:
Expand All @@ -506,7 +513,7 @@ async def get_supported_features(self):
f"Warning: Unknown feature profile detected ignoring {item}"
)
self._metrics[cdet.features.value].value = self._attr_supported_features
_LOGGER.debug("Feature profiles returned: %s", feature_list)
_LOGGER.debug("Feature profiles returned: %s", self._attr_supported_features)

async def trigger_boot_notification(self):
"""Trigger a boot notification."""
Expand Down
5 changes: 5 additions & 0 deletions custom_components/ocpp/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .const import (
CONF_CPID,
CONF_CSID,
CONF_FORCE_SMART_CHARGING,
CONF_HOST,
CONF_IDLE_INTERVAL,
CONF_MAX_CURRENT,
Expand All @@ -19,6 +20,7 @@
CONF_WEBSOCKET_PING_TRIES,
DEFAULT_CPID,
DEFAULT_CSID,
DEFAULT_FORCE_SMART_CHARGING,
DEFAULT_HOST,
DEFAULT_IDLE_INTERVAL,
DEFAULT_MAX_CURRENT,
Expand Down Expand Up @@ -60,6 +62,9 @@
vol.Required(
CONF_SKIP_SCHEMA_VALIDATION, default=DEFAULT_SKIP_SCHEMA_VALIDATION
): bool,
vol.Required(
CONF_FORCE_SMART_CHARGING, default=DEFAULT_FORCE_SMART_CHARGING
): bool,
}
)
STEP_USER_MEASURANDS_SCHEMA = vol.Schema(
Expand Down
2 changes: 2 additions & 0 deletions custom_components/ocpp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CONF_PASSWORD = ha.CONF_PASSWORD
CONF_PORT = ha.CONF_PORT
CONF_SKIP_SCHEMA_VALIDATION = "skip_schema_validation"
CONF_FORCE_SMART_CHARGING = "force_smart_charging"
CONF_SSL = "ssl"
CONF_STEP = input_number.CONF_STEP
CONF_SUBPROTOCOL = "subprotocol"
Expand All @@ -38,6 +39,7 @@
DEFAULT_MAX_CURRENT = 32
DEFAULT_PORT = 9000
DEFAULT_SKIP_SCHEMA_VALIDATION = False
DEFAULT_FORCE_SMART_CHARGING = False
DEFAULT_SSL = False
DEFAULT_SUBPROTOCOL = "ocpp1.6"
DEFAULT_METER_INTERVAL = 60
Expand Down
3 changes: 2 additions & 1 deletion custom_components/ocpp/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"websocket_ping_tries": "Verbindungsversuche vor dem Schließen des Websockets",
"websocket_ping_interval": "Websocket-Ping-Intervall (Sekunden)",
"websocket_ping_timeout": "Websocket-Ping-Timeout (Sekunden)",
"skip_schema_validation": "Überspringe OCPP-Schemavalidierung"
"skip_schema_validation": "Überspringe OCPP-Schemavalidierung",
"force_smart_charging": "Erzwinge Smart Charging Funktionsprofil"
}
},
"measurands": {
Expand Down
5 changes: 3 additions & 2 deletions custom_components/ocpp/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"websocket_ping_tries": "Websocket successive times to try connection before closing",
"websocket_ping_interval": "Websocket ping interval (seconds)",
"websocket_ping_timeout": "Websocket ping timeout (seconds)",
"skip_schema_validation": "Skip OCPP schema validation"
"skip_schema_validation": "Skip OCPP schema validation",
"force_smart_charging": "Force Smart Charging feature profile"
}
},
"measurands": {
Expand Down Expand Up @@ -57,4 +58,4 @@
"single_instance_allowed": "Only a single instance is allowed."
}
}
}
}
3 changes: 2 additions & 1 deletion custom_components/ocpp/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"websocket_ping_tries": "Reintentos de conexión Websocket",
"websocket_ping_interval": "Intervalo ping Websocket (segundos)",
"websocket_ping_timeout": "Tiempo de espera ping Websocket (segundos)",
"skip_schema_validation": "Omitir validación esquema OCPP"
"skip_schema_validation": "Omitir validación esquema OCPP",
"force_smart_charging": "Forzar perfil de función Smart Charging"
}
},
"measurands": {
Expand Down
5 changes: 3 additions & 2 deletions custom_components/ocpp/translations/i-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"websocket_ping_tries": "Websocket successive times to try connection before closing",
"websocket_ping_interval": "Websocket ping interval (seconds)",
"websocket_ping_timeout": "Websocket ping timeout (seconds)",
"skip_schema_validation": "Skip OCPP schema validation"
"skip_schema_validation": "Skip OCPP schema validation",
"force_smart_charging": "Force Smart Charging feature profile"
}
},
"measurands": {
Expand Down Expand Up @@ -57,4 +58,4 @@
"single_instance_allowed": "Only a single instance is allowed."
}
}
}
}
3 changes: 2 additions & 1 deletion custom_components/ocpp/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"websocket_ping_tries": "Websocket successive times to try connection before closing",
"websocket_ping_interval": "Websocket ping interval (secondes)",
"websocket_ping_timeout": "Websocket ping timeout (secondes)",
"skip_schema_validation": "Skip OCPP schema validation"
"skip_schema_validation": "Skip OCPP schema validation",
"force_smart_charging": "Functieprofiel Smart Charging forceren"
}
},
"measurands": {
Expand Down
15 changes: 4 additions & 11 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from custom_components.ocpp.const import (
CONF_CPID,
CONF_CSID,
CONF_FORCE_SMART_CHARGING,
CONF_HOST,
CONF_IDLE_INTERVAL,
CONF_MAX_CURRENT,
Expand All @@ -26,6 +27,7 @@
CONF_MAX_CURRENT: 32,
CONF_METER_INTERVAL: 60,
CONF_SKIP_SCHEMA_VALIDATION: False,
CONF_FORCE_SMART_CHARGING: True,
CONF_WEBSOCKET_CLOSE_TIMEOUT: 1,
CONF_WEBSOCKET_PING_TRIES: 0,
CONF_WEBSOCKET_PING_INTERVAL: 1,
Expand Down Expand Up @@ -65,6 +67,7 @@
CONF_METER_INTERVAL: 60,
CONF_MONITORED_VARIABLES: "Current.Export,Current.Import,Current.Offered,Energy.Active.Export.Register,Energy.Active.Import.Register,Energy.Reactive.Export.Register,Energy.Reactive.Import.Register,Energy.Active.Export.Interval,Energy.Active.Import.Interval,Energy.Reactive.Export.Interval,Energy.Reactive.Import.Interval,Frequency,Power.Active.Export,Power.Active.Import,Power.Factor,Power.Offered,Power.Reactive.Export,Power.Reactive.Import,RPM,SoC,Temperature,Voltage",
CONF_SKIP_SCHEMA_VALIDATION: False,
CONF_FORCE_SMART_CHARGING: True,
CONF_SSL: False,
CONF_WEBSOCKET_CLOSE_TIMEOUT: 1,
CONF_WEBSOCKET_PING_TRIES: 0,
Expand All @@ -74,20 +77,10 @@

# configuration with skip schema validation enabled
MOCK_CONFIG_DATA_2 = {
CONF_HOST: "127.0.0.1",
**MOCK_CONFIG_DATA,
CONF_PORT: 9002,
CONF_CPID: "test_cpid_2",
CONF_CSID: "test_csid",
CONF_IDLE_INTERVAL: 900,
CONF_MAX_CURRENT: 32,
CONF_METER_INTERVAL: 60,
CONF_MONITORED_VARIABLES: "Current.Export,Current.Import,Current.Offered,Energy.Active.Export.Register,Energy.Active.Import.Register,Energy.Reactive.Export.Register,Energy.Reactive.Import.Register,Energy.Active.Export.Interval,Energy.Active.Import.Interval,Energy.Reactive.Export.Interval,Energy.Reactive.Import.Interval,Frequency,Power.Active.Export,Power.Active.Import,Power.Factor,Power.Offered,Power.Reactive.Export,Power.Reactive.Import,RPM,SoC,Temperature,Voltage",
CONF_SKIP_SCHEMA_VALIDATION: True,
CONF_SSL: False,
CONF_WEBSOCKET_CLOSE_TIMEOUT: 1,
CONF_WEBSOCKET_PING_TRIES: 0,
CONF_WEBSOCKET_PING_INTERVAL: 1,
CONF_WEBSOCKET_PING_TIMEOUT: 1,
}

# separate entry for switch so tests can run concurrently
Expand Down
1 change: 1 addition & 0 deletions tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ async def test_services(hass, socket_enabled):
)
assert result

# Test MOCK_CONFIG_DATA_2
if True:
# Create a mock entry so we don't have to go through config flow
config_entry2 = MockConfigEntry(
Expand Down

0 comments on commit 9b6ce56

Please sign in to comment.