Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/crazy-max/ghaction…
Browse files Browse the repository at this point in the history
…-github-labeler-5.1.0
  • Loading branch information
lbbrhzn authored Dec 1, 2024
2 parents 5fe5554 + f4ed62e commit bdbd591
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 46 deletions.
2 changes: 1 addition & 1 deletion custom_components/ocpp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"issue_tracker": "https://github.com/lbbrhzn/ocpp/issues",
"requirements": [
"ocpp>=1.0.0",
"websockets>=12.0,<14"
"websockets>=12.0"
],
"version": "0.6.1"
}
6 changes: 5 additions & 1 deletion custom_components/ocpp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,19 @@ def device_class(self):
device_class = SensorDeviceClass.CURRENT
elif self.metric.lower().startswith("voltage"):
device_class = SensorDeviceClass.VOLTAGE
elif self.metric.lower().startswith("energy.r"):
device_class = None
elif self.metric.lower().startswith("energy."):
device_class = SensorDeviceClass.ENERGY
elif self.metric in [
Measurand.frequency,
Measurand.rpm,
] or self.metric.lower().startswith("frequency"):
device_class = SensorDeviceClass.FREQUENCY
elif self.metric.lower().startswith(("power.a", "power.o", "power.r")):
elif self.metric.lower().startswith(("power.a", "power.o")):
device_class = SensorDeviceClass.POWER
elif self.metric.lower().startswith("power.r"):
device_class = SensorDeviceClass.REACTIVE_POWER
elif self.metric.lower().startswith("temperature."):
device_class = SensorDeviceClass.TEMPERATURE
elif self.metric.lower().startswith("timestamp.") or self.metric in [
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ myst-parser==3.0.1
docutils==0.18.1
Jinja2==3.1.4
sphinx==7.1.2
sphinx_rtd_theme==3.0.1
sphinx_rtd_theme==3.0.2
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
colorlog==6.9.0
uv>=0.4
ruff==0.8.0
ruff==0.8.1
ocpp==1.0.0
websockets==13.1
websockets==14.1
jsonschema==4.23.0
pre-commit==4.0.1
pytest-homeassistant-custom-component==0.13.183
pytest-homeassistant-custom-component==0.13.186
setuptools>=70.0.0 # not directly required, pinned by Snyk to avoid a vulnerability
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
addopts = -qq --cov=custom_components.ocpp --allow-unix-socket --allow-hosts=127.0.0.1
console_output_style = count
asyncio_mode = auto
asyncio_default_fixture_loop_scope = function

[coverage:report]
show_missing = true
Expand Down
68 changes: 28 additions & 40 deletions tests/test_charge_point_v16.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ async def test_services(hass, cs, socket_enabled):
await hass.async_block_till_done()

# no subprotocol
# NB each new config entry will trigger async_update_entry
# if the charger measurands differ from the config entry
# which causes the websocket server to close/restart with a
# ConnectionClosedOK exception, hence it needs to be passed/suppressed
async with websockets.connect(
"ws://127.0.0.1:9002/CP_1_nosub",
) as ws2:
# use a different id for debugging
cp2 = ChargePoint("CP_1_no_subprotocol", ws2)
with contextlib.suppress(asyncio.TimeoutError):
with contextlib.suppress(
asyncio.TimeoutError, websockets.exceptions.ConnectionClosedOK
):
await asyncio.wait_for(
asyncio.gather(
cp2.start(),
Expand Down Expand Up @@ -177,17 +183,8 @@ async def test_services(hass, cs, socket_enabled):
await asyncio.wait_for(
asyncio.gather(
cp.start(),
cp.send_boot_notification(),
cp.send_authorize(),
cp.send_heartbeat(),
cp.send_status_notification(),
cp.send_firmware_status(),
cp.send_data_transfer(),
cp.send_start_transaction(),
cp.send_stop_transaction(),
cp.send_meter_periodic_data(),
),
timeout=5,
timeout=3,
)
await ws.close()

Expand All @@ -204,17 +201,8 @@ async def test_services(hass, cs, socket_enabled):
await asyncio.wait_for(
asyncio.gather(
cp.start(),
cp.send_boot_notification(),
cp.send_authorize(),
cp.send_heartbeat(),
cp.send_status_notification(),
cp.send_firmware_status(),
cp.send_data_transfer(),
cp.send_start_transaction(),
cp.send_stop_transaction(),
cp.send_meter_periodic_data(),
),
timeout=5,
timeout=3,
)
await ws.close()

Expand All @@ -235,7 +223,7 @@ async def test_services(hass, cs, socket_enabled):
cp.start(),
cp.send_meter_periodic_data(),
),
timeout=5,
timeout=3,
)
# check if None
assert cs.get_metric("test_cpid", "Energy.Meter.Start") is None
Expand All @@ -247,7 +235,7 @@ async def test_services(hass, cs, socket_enabled):
cp.send_start_transaction(12344),
cp.send_meter_periodic_data(),
),
timeout=5,
timeout=3,
)
# save for reference the values for meter_start and transaction_id
saved_meter_start = int(cs.get_metric("test_cpid", "Energy.Meter.Start"))
Expand All @@ -261,7 +249,7 @@ async def test_services(hass, cs, socket_enabled):
asyncio.gather(
cp.send_meter_periodic_data(),
),
timeout=5,
timeout=3,
)
await ws.close()

Expand Down Expand Up @@ -423,9 +411,11 @@ async def test_services(hass, cs, socket_enabled):
"ws://127.0.0.1:9000/CP_1_error",
subprotocols=["ocpp1.6"],
) as ws:
cp = ChargePoint("CP_1_error", ws)
cp.accept = False
try:
with contextlib.suppress(
asyncio.TimeoutError, websockets.exceptions.ConnectionClosedOK
):
cp = ChargePoint("CP_1_error", ws)
cp.accept = False
await asyncio.wait_for(
asyncio.gather(
cp.start(),
Expand All @@ -437,23 +427,21 @@ async def test_services(hass, cs, socket_enabled):
),
timeout=3,
)
except TimeoutError:
pass
except websockets.exceptions.ConnectionClosedOK:
pass
await ws.close()

await asyncio.sleep(1)

# setting state no longer available with websockets >14
# test ping timeout, change cpid to start new connection
cs.settings.cpid = "CP_3_test"
async with websockets.connect(
"ws://127.0.0.1:9000/CP_3",
subprotocols=["ocpp1.6"],
) as ws:
cp = ChargePoint("CP_3_test", ws)
ws.state = 3 # CLOSED = 3
await asyncio.sleep(3)
await ws.close()
# cs.settings.cpid = "CP_3_test"
# async with websockets.connect(
# "ws://127.0.0.1:9000/CP_3",
# subprotocols=["ocpp1.6"],
# ) as ws:
# cp = ChargePoint("CP_3_test", ws)
# ws.state = 3 # CLOSED = 3
# await asyncio.sleep(3)
# await ws.close()

# test services when charger is unavailable
await asyncio.sleep(1)
Expand Down

0 comments on commit bdbd591

Please sign in to comment.