Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ black==21.7b0
flake8==3.9.2
reorder-python-imports==2.5.0
websockets==9.1
sqlalchemy==1.4.21
sqlalchemy==1.4.17
ocpp>=0.8.3
46 changes: 24 additions & 22 deletions custom_components/ocpp/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,39 @@

from homeassistant.components.switch import SwitchEntity

from ocpp.v16.enums import ChargePointStatus

from .api import CentralSystem
from .const import (
CONF_CPID,
DOMAIN,
ICON,
SERVICE_AVAILABILITY,
SERVICE_CHARGE_START,
SERVICE_CHARGE_STOP,
SERVICE_RESET,
SERVICE_UNLOCK,
)
from .const import CONF_CPID, DOMAIN, ICON
from .enums import HAChargerServices, HAChargerStatuses

# At a minimum define switch name and on service call, pulse used to call a service once such as reset
# metric and condition combination can be used to drive switch state, use default to set initial state to True
SWITCH_CHARGE = {
"name": "Charge_Control",
"on": SERVICE_CHARGE_START,
"off": SERVICE_CHARGE_STOP,
"metric": "Status",
"condition": "Charging",
"on": HAChargerServices.service_charge_start.name,
"off": HAChargerServices.service_charge_stop.name,
"metric": HAChargerStatuses.status.value,
"condition": ChargePointStatus.charging.value,
}
SWITCH_AVAILABILITY = {
"name": "Availability",
"on": SERVICE_AVAILABILITY,
"off": SERVICE_AVAILABILITY,
"on": HAChargerServices.service_availability.name,
"off": HAChargerServices.service_availability.name,
"default": True,
"metric": HAChargerStatuses.status.value,
"condition": ChargePointStatus.available.value,
}
SWITCH_RESET = {
"name": "Reset",
"on": HAChargerServices.service_reset.name,
"pulse": True,
}
SWITCH_UNLOCK = {
"name": "Unlock",
"on": HAChargerServices.service_unlock.name,
"pulse": True,
}
SWITCH_RESET = {"name": "Reset", "on": SERVICE_RESET, "pulse": True}
SWITCH_UNLOCK = {"name": "Unlock", "on": SERVICE_UNLOCK, "pulse": True}


async def async_setup_entry(hass, entry, async_add_devices):
Expand All @@ -41,10 +45,8 @@ async def async_setup_entry(hass, entry, async_add_devices):

entities = []

entities.append(ChargePointSwitch(central_system, cp_id, SWITCH_CHARGE))
entities.append(ChargePointSwitch(central_system, cp_id, SWITCH_AVAILABILITY))
entities.append(ChargePointSwitch(central_system, cp_id, SWITCH_RESET))
entities.append(ChargePointSwitch(central_system, cp_id, SWITCH_UNLOCK))
for ent in [SWITCH_CHARGE, SWITCH_AVAILABILITY, SWITCH_RESET, SWITCH_UNLOCK]:
entities.append(ChargePointSwitch(central_system, cp_id, ent))

async_add_devices(entities, False)

Expand Down