Skip to content

Commit 5e29d62

Browse files
authored
feat: add mqtt connection status property (#245)
* feat: add mqtt connection status property * formatting * update tests * remove unneeded return * linting
1 parent c3e5c49 commit 5e29d62

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

openevsehttp/__main__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,3 +1020,10 @@ def max_amps(self) -> int:
10201020
if self._config is not None and "max_current_hard" in self._config:
10211021
return self._config["max_current_hard"]
10221022
return MAX_AMPS
1023+
1024+
@property
1025+
def mqtt_connected(self) -> bool:
1026+
"""Return the status of the mqtt connection."""
1027+
if self._status is not None and "mqtt_connected" in self._status:
1028+
return self._status["mqtt_connected"]
1029+
return False

tests/fixtures/v2_json/status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"mode":"STA","wifi_client_connected":1,"net_connected":1,"srssi":-56,"ipaddress":"192.168.1.67","emoncms_connected":0,"packets_sent":2909,"packets_success":0,"mqtt_connected":1,"ohm_hour":"NotConnected","free_heap":12448,"comm_sent":43704,"comm_success":43704,"rapi_connected":1,"amp":0,"voltage":240,"pilot":25,"temp1":340,"temp2":false,"temp3":false,"state":1,"elapsed":8751,"wattsec":25212279,"watthour":1585443,"gfcicount":0,"nogndcount":0,"stuckcount":0,"divertmode":1,"solar":0,"grid_ie":0,"charge_rate":0,"divert_update":87648,"ota_update":0}
1+
{"mode":"STA","wifi_client_connected":1,"net_connected":1,"srssi":-56,"ipaddress":"192.168.1.67","emoncms_connected":0,"packets_sent":2909,"packets_success":0,"mqtt_connected":0,"ohm_hour":"NotConnected","free_heap":12448,"comm_sent":43704,"comm_success":43704,"rapi_connected":1,"amp":0,"voltage":240,"pilot":25,"temp1":340,"temp2":false,"temp3":false,"state":1,"elapsed":8751,"wattsec":25212279,"watthour":1585443,"gfcicount":0,"nogndcount":0,"stuckcount":0,"divertmode":1,"solar":0,"grid_ie":0,"charge_rate":0,"divert_update":87648,"ota_update":0}

tests/fixtures/v4_json/status-broken.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"emoncms_connected": 0,
88
"packets_sent": 0,
99
"packets_success": 0,
10-
"mqtt_connected": 1,
1110
"ohm_hour": "NotConnected",
1211
"free_heap": 223464,
1312
"comm_sent": 345660,

tests/test_main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,3 +1485,19 @@ async def test_get_state_raw(fixture, expected, request):
14851485
await charger.update()
14861486
status = charger.state_raw
14871487
assert status == expected
1488+
1489+
1490+
@pytest.mark.parametrize(
1491+
"fixture, expected",
1492+
[
1493+
("test_charger", True),
1494+
("test_charger_v2", False),
1495+
("test_charger_broken", False),
1496+
],
1497+
)
1498+
async def test_get_state_raw(fixture, expected, request):
1499+
"""Test v4 Status reply."""
1500+
charger = request.getfixturevalue(fixture)
1501+
await charger.update()
1502+
status = charger.mqtt_connected
1503+
assert status == expected

0 commit comments

Comments
 (0)