Skip to content

Commit b0d2dca

Browse files
authored
Merge branch 'main' into dependabot/pip/dot-github/workflows/black-22.12.0
2 parents 4f2891f + 8f19a20 commit b0d2dca

File tree

12 files changed

+77
-30
lines changed

12 files changed

+77
-30
lines changed

.github/workflows/constraints.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ pip>=8.0.3,<22.4
33
pre-commit==2.20.0
44
bandit==1.7.4
55
black==22.12.0
6-
flake8==5.0.4
6+
flake8==6.0.0
77
isort==5.10.1
88
pre-comit-hooks==4.1.0
9-
pyupgrade==3.2.0
9+
pyupgrade==3.3.1
1010
reorder-python-imports==3.9.0
1111
sqlalchemy>=1.4.23

custom_components/ocpp/button.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async def async_setup_entry(hass, entry, async_add_devices):
5959
class ChargePointButton(ButtonEntity):
6060
"""Individual button for charge point."""
6161

62+
_attr_has_entity_name = True
6263
entity_description: OcppButtonDescription
6364

6465
def __init__(
@@ -74,14 +75,11 @@ def __init__(
7475
self._attr_unique_id = ".".join(
7576
[BUTTON_DOMAIN, DOMAIN, self.cp_id, self.entity_description.key]
7677
)
77-
self._attr_name = ".".join([self.cp_id, self.entity_description.name])
78+
self._attr_name = self.entity_description.name
7879
self._attr_device_info = DeviceInfo(
7980
identifiers={(DOMAIN, self.cp_id)},
8081
via_device=(DOMAIN, self.central_system.id),
8182
)
82-
self.entity_id = (
83-
BUTTON_DOMAIN + "." + "_".join([self.cp_id, self.entity_description.key])
84-
)
8583

8684
@property
8785
def available(self) -> bool:

custom_components/ocpp/const.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Define constants for OCPP integration."""
22
import homeassistant.components.input_number as input_number
3+
from homeassistant.components.sensor import SensorDeviceClass
34
import homeassistant.const as ha
45

56
from ocpp.v16.enums import Measurand, UnitOfMeasure
@@ -95,21 +96,31 @@
9596

9697
# Where a HA unit does not exist use Ocpp unit
9798
UNITS_OCCP_TO_HA = {
98-
UnitOfMeasure.wh: ha.ENERGY_WATT_HOUR,
99-
UnitOfMeasure.kwh: ha.ENERGY_KILO_WATT_HOUR,
99+
UnitOfMeasure.wh: ha.UnitOfEnergy.WATT_HOUR,
100+
UnitOfMeasure.kwh: ha.UnitOfEnergy.KILO_WATT_HOUR,
100101
UnitOfMeasure.varh: UnitOfMeasure.varh,
101102
UnitOfMeasure.kvarh: UnitOfMeasure.kvarh,
102-
UnitOfMeasure.w: ha.POWER_WATT,
103-
UnitOfMeasure.kw: ha.POWER_KILO_WATT,
104-
UnitOfMeasure.va: ha.POWER_VOLT_AMPERE,
103+
UnitOfMeasure.w: ha.UnitOfPower.WATT,
104+
UnitOfMeasure.kw: ha.UnitOfPower.KILO_WATT,
105+
UnitOfMeasure.va: ha.UnitOfApparentPower.VOLT_AMPERE,
105106
UnitOfMeasure.kva: UnitOfMeasure.kva,
106107
UnitOfMeasure.var: UnitOfMeasure.var,
107108
UnitOfMeasure.kvar: UnitOfMeasure.kvar,
108-
UnitOfMeasure.a: ha.ELECTRIC_CURRENT_AMPERE,
109-
UnitOfMeasure.v: ha.ELECTRIC_POTENTIAL_VOLT,
110-
UnitOfMeasure.celsius: ha.TEMP_CELSIUS,
111-
UnitOfMeasure.fahrenheit: ha.TEMP_FAHRENHEIT,
112-
UnitOfMeasure.k: ha.TEMP_KELVIN,
109+
UnitOfMeasure.a: ha.UnitOfElectricCurrent.AMPERE,
110+
UnitOfMeasure.v: ha.UnitOfElectricPotential.VOLT,
111+
UnitOfMeasure.celsius: ha.UnitOfTemperature.CELSIUS,
112+
UnitOfMeasure.fahrenheit: ha.UnitOfTemperature.FAHRENHEIT,
113+
UnitOfMeasure.k: ha.UnitOfTemperature.KELVIN,
113114
UnitOfMeasure.percent: ha.PERCENTAGE,
114-
UnitOfMeasure.hertz: ha.FREQUENCY_HERTZ,
115+
UnitOfMeasure.hertz: ha.UnitOfFrequency.HERTZ,
116+
}
117+
118+
# Where an occp unit is not reported and only one possibility assign HA unit on device class
119+
DEFAULT_CLASS_UNITS_HA = {
120+
SensorDeviceClass.CURRENT: ha.UnitOfElectricCurrent.AMPERE,
121+
SensorDeviceClass.VOLTAGE: ha.UnitOfElectricPotential.VOLT,
122+
SensorDeviceClass.FREQUENCY: ha.UnitOfFrequency.HERTZ,
123+
SensorDeviceClass.BATTERY: ha.PERCENTAGE,
124+
SensorDeviceClass.POWER: ha.UnitOfPower.KILO_WATT,
125+
SensorDeviceClass.ENERGY: ha.UnitOfEnergy.KILO_WATT_HOUR,
115126
}

custom_components/ocpp/number.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
NumberEntityDescription,
1111
RestoreNumber,
1212
)
13+
from homeassistant.const import ELECTRIC_CURRENT_AMPERE
1314
from homeassistant.core import HomeAssistant, callback
1415
from homeassistant.helpers.dispatcher import async_dispatcher_connect
1516
from homeassistant.helpers.entity import DeviceInfo
@@ -37,12 +38,13 @@ class OcppNumberDescription(NumberEntityDescription):
3738
NUMBERS: Final = [
3839
OcppNumberDescription(
3940
key="maximum_current",
40-
name="Maximum_Current",
41+
name="Maximum Current",
4142
icon=ICON,
4243
initial_value=DEFAULT_MAX_CURRENT,
4344
native_min_value=0,
4445
native_max_value=DEFAULT_MAX_CURRENT,
4546
native_step=1,
47+
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
4648
),
4749
]
4850

custom_components/ocpp/sensor.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
1919

2020
from .api import CentralSystem
21-
from .const import CONF_CPID, DATA_UPDATED, DEFAULT_CPID, DOMAIN, ICON, Measurand
21+
from .const import (
22+
CONF_CPID,
23+
DATA_UPDATED,
24+
DEFAULT_CLASS_UNITS_HA,
25+
DEFAULT_CPID,
26+
DOMAIN,
27+
ICON,
28+
Measurand,
29+
)
2230
from .enums import HAChargerDetails, HAChargerSession, HAChargerStatuses
2331

2432

@@ -27,6 +35,7 @@ class OcppSensorDescription(SensorEntityDescription):
2735
"""Class to describe a Sensor entity."""
2836

2937
scale: int = 1 # used for rounding metric
38+
metric: str | None = None
3039

3140

3241
async def async_setup_entry(hass, entry, async_add_devices):
@@ -41,14 +50,16 @@ async def async_setup_entry(hass, entry, async_add_devices):
4150
SENSORS.append(
4251
OcppSensorDescription(
4352
key=metric.lower(),
44-
name=metric,
53+
name=metric.replace(".", " "),
54+
metric=metric,
4555
)
4656
)
4757
for metric in list(HAChargerStatuses) + list(HAChargerDetails):
4858
SENSORS.append(
4959
OcppSensorDescription(
5060
key=metric.lower(),
51-
name=metric,
61+
name=metric.replace(".", " "),
62+
metric=metric,
5263
entity_category=EntityCategory.DIAGNOSTIC,
5364
)
5465
)
@@ -83,7 +94,7 @@ def __init__(
8394
self.central_system = central_system
8495
self.cp_id = cp_id
8596
self.entity_description = description
86-
self.metric = self.entity_description.name
97+
self.metric = self.entity_description.metric
8798
self._hass = hass
8899
self._extra_attr = {}
89100
self._last_reset = homeassistant.util.dt.utc_from_timestamp(0)
@@ -182,6 +193,10 @@ def native_unit_of_measurement(self):
182193
value = self.central_system.get_ha_unit(self.cp_id, self.metric)
183194
if value is not None:
184195
self._attr_native_unit_of_measurement = value
196+
else:
197+
self._attr_native_unit_of_measurement = DEFAULT_CLASS_UNITS_HA.get(
198+
self.device_class
199+
)
185200
return self._attr_native_unit_of_measurement
186201

187202
async def async_added_to_hass(self) -> None:

custom_components/ocpp/switch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OcppSwitchDescription(SwitchEntityDescription):
3636
SWITCHES: Final = [
3737
OcppSwitchDescription(
3838
key="charge_control",
39-
name="Charge_Control",
39+
name="Charge Control",
4040
icon=ICON,
4141
on_action=HAChargerServices.service_charge_start.name,
4242
off_action=HAChargerServices.service_charge_stop.name,

docs/supported-devices.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All OCPP 1.6j compatible devices should be supported, but not every device offer
88
## [Alfen - Eve Single Pro-line](https://alfen.com/en/ev-charge-points/alfen-product-range)
99
## [Alfen - Eve Single S-line](https://alfen.com/en/ev-charge-points/alfen-product-range)
1010
## [CTEK Chargestorm Connected 2](https://www.ctek.com/uk/ev-charging/chargestorm%C2%AE-connected-2)
11+
[Jonas Karlsson](https://github.com/jonasbkarlsson) has written a [getting started guide](https://github.com/jonasbkarlsson/ocpp/wiki/CTEK-Chargestorm-Connected-2) for connecting CTEK Chargestorm Connected 2.
1112
## [EVBox Elvi](https://evbox.com/en/ev-chargers/elvi)
1213
## [EVLink Wallbox Plus](https://www.se.com/ww/en/product/EVH3S22P0CK/evlink-wallbox-plus---t2-attached-cable---3-phase---32a-22kw/)
1314
## [Evnex E Series & X Series Charging Stations](https://www.evnex.com/)

docs/user-guide.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ The Grizzl-E updates these metrics every 30s during charging sessions:
9090
* `Availability` (ON when charger is idle. OFF during active charging session, or when something causes a problem)
9191
* `Maximum Current` (sets maximum charging current available. Reverts to value set by charger's internal DIP switch following reboots; tweak slider to reload)
9292

93+
## Useful Entities for Vestel EVC-04 Wallboxes
94+
95+
### Metrics
96+
97+
* `Energy Active Import Register` (cumulative energy supplied to EV during charging session. Resets to zero at start of each session)
98+
* `Energy Active Import Interval` (in case you need the energy spent in total for the current charging session)
99+
* `Power Active Import` (instantaneous charging power)
100+
* `Current Import`
101+
* `Time Session` (elapsed time from start of charging session)
102+
103+
### Diagnostics
104+
105+
* `Status Connector` (shows the current state of available/preparing/charging/finishing/suspended etc)
106+
* `Stop Reason` (reason the charging session was stopped)
107+
108+
### Controls
109+
110+
* `Charge Control`
111+
* `Availability` (must be set to ON before EV is plugged in)
112+
* `Maximum Current` (sets maximum charging current available)
113+
* `Reset`
114+
93115
### OCPP Compatibility Issues
94116

95117
Grizzl-E firmware has a few OCPP-compliance defects, including responding to certain OCPP server messages with invalid JSON. Symptoms of this problem include repeated reboots of the charger. By editing the OCPP server source code, one can avoid these problematic messages and obtain useful charger behaviour. ChargeLabs (the company working on the Grizzl-E firmware) expects to release version 6 of the firmware in early 2023, which may fix these problems.

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
homeassistant>=2021.12.0
1+
homeassistant>=2023.1.0b1
22
ocpp==0.15.0
33
websockets==10.4

0 commit comments

Comments
 (0)