|
16 | 16 | AlreadyListening, |
17 | 17 | AuthenticationError, |
18 | 18 | MissingMethod, |
| 19 | + MissingSerial, |
19 | 20 | ParseJSONError, |
20 | 21 | UnknownError, |
21 | 22 | ) |
@@ -287,6 +288,28 @@ async def update(self) -> None: |
287 | 288 | self.url, self._update_status, self._user, self._pwd |
288 | 289 | ) |
289 | 290 |
|
| 291 | + async def test_and_get(self) -> dict: |
| 292 | + """Test connection. |
| 293 | +
|
| 294 | + Return model serial number as dict |
| 295 | + """ |
| 296 | + url = f"{self.url}config" |
| 297 | + data = {} |
| 298 | + |
| 299 | + response = await self.process_request(url, method="get") |
| 300 | + if "wifi_serial" in response: |
| 301 | + serial = response["wifi_serial"] |
| 302 | + else: |
| 303 | + _LOGGER.debug("Older firmware detected, missing serial.") |
| 304 | + raise MissingSerial |
| 305 | + if "buildenv" in response: |
| 306 | + model = response["buildenv"] |
| 307 | + else: |
| 308 | + model = "unknown" |
| 309 | + |
| 310 | + data = {"serial": serial, "model": model} |
| 311 | + return data |
| 312 | + |
290 | 313 | def ws_start(self): |
291 | 314 | """Start the websocket listener.""" |
292 | 315 | if self._ws_listening: |
@@ -503,6 +526,14 @@ async def set_current(self, amps: int = 6) -> None: |
503 | 526 | response = await self.send_command(command) |
504 | 527 | _LOGGER.debug("Set current response: %s", response[1]) |
505 | 528 |
|
| 529 | + # Restart OpenEVSE WiFi |
| 530 | + async def restart_wifi(self) -> None: |
| 531 | + """Restart OpenEVSE Wifi module.""" |
| 532 | + url = f"{self.url}restart" |
| 533 | + |
| 534 | + response = await self.process_request(url=url, method="get") |
| 535 | + _LOGGER.debug("Restart response: %s", response) |
| 536 | + |
506 | 537 | @property |
507 | 538 | def hostname(self) -> str: |
508 | 539 | """Return charger hostname.""" |
@@ -793,14 +824,16 @@ def wifi_serial(self) -> str | None: |
793 | 824 | return None |
794 | 825 |
|
795 | 826 | @property |
796 | | - def charging_power(self) -> float: |
| 827 | + def charging_power(self) -> float | None: |
797 | 828 | """Return the charge power. |
798 | 829 |
|
799 | 830 | Calculate Watts base on V*I |
800 | 831 | """ |
801 | | - assert self._status is not None |
802 | | - value = round(self._status["voltage"] * self._status["amp"], 2) |
803 | | - return value |
| 832 | + if self._status is not None and any( |
| 833 | + key in self._status for key in ["voltage", "amp"] |
| 834 | + ): |
| 835 | + return round(self._status["voltage"] * self._status["amp"], 2) |
| 836 | + return None |
804 | 837 |
|
805 | 838 | # There is currently no min/max amps JSON data |
806 | 839 | # available via HTTP API methods |
|
0 commit comments