Skip to content

Commit

Permalink
ocpp: significant repo update (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
drc38 authored Jul 16, 2021
1 parent 5dd23d8 commit f66f167
Show file tree
Hide file tree
Showing 9 changed files with 919 additions and 199 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ jobs:
--durations=10 \
-n auto \
-p no:sugar \
-rA \
tests
438 changes: 288 additions & 150 deletions custom_components/ocpp/api.py

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions custom_components/ocpp/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"""Additional enumerated values to use in home assistant."""
from enum import Enum


class HAChargerServices(str, Enum):
"""Charger status conditions to report in home assistant."""

"""For HA service reference use .name for function to call use .value"""

service_charge_start = "start_transaction"
service_charge_stop = "stop_transaction"
service_availability = "availability"
service_set_charge_rate = "set_charge_rate"
service_reset = "reset"
service_unlock = "unlock"
service_update_firmware = "update_firmware"
service_configure = "configure"
service_get_configuration = "get_configuration"
service_clear_profile = "clear_profile"


class HAChargerStatuses(str, Enum):
"""Charger status conditions to report in home assistant."""

status = "Status"
heartbeat = "Heartbeat"
error_code = "Error.Code"
stop_reason = "Stop.Reason"
firmware_status = "FW.Status"


class HAChargerDetails(str, Enum):
"""Charger nameplate information to report in home assistant."""

identifier = "ID"
model = "Model"
vendor = "Vendor"
serial = "Serial"
firmware_version = "FW.Version"
features = "Features"
connectors = "Connectors"


class HAChargerSession(str, Enum):
"""Charger session information to report in home assistant."""

transaction_id = "Transaction.Id"
session_time = "Session.Time" # in min
session_energy = "Session.Energy" # in kWh
meter_start = "Meter.Start" # in kWh


class OcppMisc(str, Enum):
"""Miscellaneous strings used in ocpp v1.6 responses."""

"""For pythonic version use .name (eg with kwargs) for ocpp json use .value"""

limit = "limit"
measurand = "measurand"
reason = "reason"
readonly = "readonly"
status = "status"
transaction_id = "transactionId"
charge_point_serial_number = "chargePointSerialNumber"
charge_point_vendor = "chargePointVendor"
charge_point_model = "chargePointModel"
firmware_version = "firmwareVersion"
charging_profile_id = "chargingProfileId"
stack_level = "stackLevel"
charging_profile_kind = "chargingProfileKind"
charging_profile_purpose = "chargingProfilePurpose"
charging_schedule = "chargingSchedule"
charging_rate_unit = "chargingRateUnit"
charging_schedule_period = "chargingSchedulePeriod"
start_period = "startPeriod"
feature_profile_core = "Core"
feature_profile_firmware = "FirmwareManagement"
feature_profile_smart = "SmartCharging"
feature_profile_reservation = "Reservation"
feature_profile_remote = "RemoteTrigger"
feature_profile_auth = "LocalAuthListManagement"

# for use with Smart Charging
current = "Current"
power = "Power"


class ConfigurationKey(str, Enum):
"""Configuration Key Names."""

# 9.1 Core Profile
allow_offline_tx_for_unknown_id = "AllowOfflineTxForUnknownId"
authorization_cache_enabled = "AuthorizationCacheEnabled"
authorize_remote_tx_requests = "AuthorizeRemoteTxRequests"
blink_repeat = "BlinkRepeat"
clock_aligned_data_interval = "ClockAlignedDataInterval"
connection_time_out = "ConnectionTimeOut"
connector_phase_rotation = "ConnectorPhaseRotation"
connector_phase_rotation_max_length = "ConnectorPhaseRotationMaxLength"
get_configuration_max_keys = "GetConfigurationMaxKeys"
heartbeat_interval = "HeartbeatInterval"
light_intensity = "LightIntensity"
local_authorize_offline = "LocalAuthorizeOffline"
local_pre_authorize = "LocalPreAuthorize"
max_energy_on_invalid_id = "MaxEnergyOnInvalidId"
meter_values_aligned_data = "MeterValuesAlignedData"
meter_values_aligned_data_max_length = "MeterValuesAlignedDataMaxLength"
meter_values_sampled_data = "MeterValuesSampledData"
meter_values_sampled_data_max_length = "MeterValuesSampledDataMaxLength"
meter_value_sample_interval = "MeterValueSampleInterval"
minimum_status_duration = "MinimumStatusDuration"
number_of_connectors = "NumberOfConnectors"
reset_retries = "ResetRetries"
stop_transaction_on_ev_side_disconnect = "StopTransactionOnEVSideDisconnect"
stop_transaction_on_invalid_id = "StopTransactionOnInvalidId"
stop_txn_aligned_data = "StopTxnAlignedData"
stop_txn_aligned_data_max_length = "StopTxnAlignedDataMaxLength"
stop_txn_sampled_data = "StopTxnSampledData"
stop_txn_sampled_data_max_length = "StopTxnSampledDataMaxLength"
supported_feature_profiles = "SupportedFeatureProfiles"
supported_feature_profiles_max_length = "SupportedFeatureProfilesMaxLength"
transaction_message_attempts = "TransactionMessageAttempts"
transaction_message_retry_interval = "TransactionMessageRetryInterval"
unlock_connector_on_ev_side_disconnect = "UnlockConnectorOnEVSideDisconnect"
web_socket_ping_interval = "WebSocketPingInterval"

# 9.2 Local Auth List Management Profile
local_auth_list_enabled = "LocalAuthListEnabled"
local_auth_list_max_length = "LocalAuthListMaxLength"
send_local_list_max_length = "SendLocalListMaxLength"

# 9.3 Reservation Profile
reserve_connector_zero_supported = "ReserveConnectorZeroSupported"

# 9.4 Smart Charging Profile
charge_profile_max_stack_level = "ChargeProfileMaxStackLevel"
charging_schedule_allowed_charging_rate_unit = (
"ChargingScheduleAllowedChargingRateUnit"
)
charging_schedule_max_periods = "ChargingScheduleMaxPeriods"
connector_switch_3to1_phase_supported = "ConnectorSwitch3to1PhaseSupported"
max_charging_profiles_installed = "MaxChargingProfilesInstalled"
88 changes: 71 additions & 17 deletions custom_components/ocpp/services.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,83 @@
# Service ID
#start_charge:
set_charge_rate:
# Service name as shown in UI
# name: Start charging
name: Set maximum charge rate
# Description of the service
# description: Starts a charge session
description: Sets the maximum charge rate in Amps or Watts (dependent on charger support)
# If the service accepts entity IDs, target allows the user to specify entities by entity, device, or area. If `target` is specified, `entity_id` should not be defined in the `fields` map. By default it shows only targets matching entities from the same domain as the service, but if further customization is required, target supports the entity, device, and area selectors (https://www.home-assistant.io/docs/blueprint/selectors/). Entity selector parameters will automatically be applied to device and area, and device selector parameters will automatically be applied to area.
# target:
#target:
# entity:
# integration: ocpp
# Different fields that your service accepts
# limit:
fields:
# Key of the field
limit_amps:
# Field name as shown in UI
# name: Charge limit
name: Limit (A)
# Description of the field
# description: Maximum charge rate in W
description: Maximum charge rate in Amps
# Whether or not field is required (default = false)
# required: false
required: false
# Advanced fields are only shown when the advanced mode is enabled for the user (default = false)
# advanced: false
advanced: true
# Example value that can be passed for this field
# example: "1500"
example: 16
# The default field value
# default: "22000"
default: 32
limit_watts:
name: Limit (W)
description: Maximum charge rate in Watts
required: false
advanced: true
example: 1500
default: 22000

#stop_charge:
# name: Stop charging
# description: Stops a charge session in progress
# target:
# entity:
# integration: ocpp
clear_profile:
name: Clear charging profiles
description: Clears all charging profiles (limits) set (dependent on charger support)

update_firmware:
name: Update charger firmware
description: Specify server to download firmware and time to delay updating (dependent on charger support)
fields:
firmware_url:
name: Url of firmware
description: Full url of firmware file (http or https)
required: true
advanced: true
example: "http://www.charger.com/firmware.bin"
delay_hours:
name: Delay hours
description: Hours to delay charger update
required: false
advanced: true
example: 12
default: 0

configure:
name: Configure charger features
description: Change supported Ocpp v1.6 configuration values
fields:
ocpp_key:
name: Configuration key name
description: Write-enabled key name supported
required: true
advanced: true
example: "WebSocketPingInterval"
value:
name: Key value
description: Value to write to key
required: true
advanced: true
example: "60"

get_configuration:
name: Get configuration values for charger
description: Change supported Ocpp v1.6 configuration values
fields:
ocpp_key:
name: Configuration key name
description: Key name supported
required: true
advanced: true
example: "WebSocketPingInterval"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ branch = False

[coverage:report]
show_missing = true
fail_under = 100
fail_under = 75
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def skip_notifications_fixture():
def bypass_get_data_fixture():
"""Skip calls to get data from API."""
# with patch("custom_components.ocpp.ocppApiClient.async_get_data"):
# yield
yield


# In this fixture, we are forcing calls to async_get_data to raise an Exception. This is useful
Expand All @@ -42,4 +42,4 @@ def error_get_data_fixture():
# "custom_components.ocpp.ocppApiClient.async_get_data",
# side_effect=Exception,
# ):
# yield
yield
9 changes: 9 additions & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@
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",
}
# separate entry for switch so tests can run concurrently
MOCK_CONFIG_SWITCH = {
CONF_HOST: "0.0.0.0",
CONF_PORT: 9001,
CONF_CPID: "test_cpid_2",
CONF_CSID: "test_csid_2",
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",
}
DEFAULT_NAME = "test"
Loading

0 comments on commit f66f167

Please sign in to comment.