python-openevse-http 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
openevsehttp/client.py CHANGED
@@ -6,7 +6,6 @@ import asyncio
6
6
  import inspect
7
7
  import json
8
8
  import logging
9
- import re
10
9
  import threading
11
10
  from collections.abc import Callable, Mapping
12
11
  from typing import Any
@@ -31,6 +30,7 @@ from .exceptions import (
31
30
  from .managers import ManagersMixin
32
31
  from .properties import PropertiesMixin
33
32
  from .sensors import SensorsMixin
33
+ from .utils import get_awesome_version
34
34
  from .websocket import (
35
35
  SIGNAL_CONNECTION_STATE,
36
36
  STATE_CONNECTED,
@@ -139,7 +139,7 @@ class OpenEVSE(CommandsMixin, ManagersMixin, SensorsMixin, PropertiesMixin):
139
139
  try:
140
140
  message = json.loads(message)
141
141
  except ValueError:
142
- _LOGGER.warning("Non JSON response: %s", message)
142
+ _LOGGER.debug("Non JSON response: %s", message)
143
143
 
144
144
  if resp.status == 400:
145
145
  if isinstance(message, dict) and "msg" in message:
@@ -438,41 +438,21 @@ class OpenEVSE(CommandsMixin, ManagersMixin, SensorsMixin, PropertiesMixin):
438
438
  """Return bool if minimum version is met."""
439
439
  if "version" not in self._config:
440
440
  # Throw warning if we can't find the version
441
- _LOGGER.warning("Unable to find firmware version.")
441
+ _LOGGER.debug("Unable to find firmware version.")
442
442
  return False
443
443
  cutoff = AwesomeVersion(min_version)
444
- current = ""
445
444
  limit = ""
446
445
  if max_version != "":
447
446
  limit = AwesomeVersion(max_version)
448
447
 
449
- firmware_filtered = None
450
- firmware_search = re.search(r"\d+\.\d+\.\d+", self._config["version"])
451
- if firmware_search:
452
- firmware_filtered = firmware_search.group(0)
453
-
454
- if firmware_filtered is None:
455
- _LOGGER.warning(
456
- "Non-standard versioning string: %s", self._config["version"]
448
+ current = get_awesome_version(self._config["version"])
449
+ if current.strategy == "unknown":
450
+ _LOGGER.debug(
451
+ "Non-semver firmware version detected: %s",
452
+ self._config["version"],
457
453
  )
458
- _LOGGER.debug("Non-semver firmware version detected.")
459
454
  return False
460
455
 
461
- _LOGGER.debug("Detected firmware: %s", self._config["version"])
462
- _LOGGER.debug("Filtered firmware: %s", firmware_filtered)
463
-
464
- if "dev" in self._config["version"]:
465
- value = self._config["version"]
466
- _LOGGER.debug("Stripping 'dev' from version.")
467
- value = value.split(".")
468
- value = ".".join(value[0:3])
469
- elif "master" in self._config["version"]:
470
- value = "dev"
471
- else:
472
- value = firmware_filtered
473
-
474
- current = AwesomeVersion(value)
475
-
476
456
  if limit:
477
457
  try:
478
458
  if cutoff <= current < limit:
openevsehttp/commands.py CHANGED
@@ -14,6 +14,7 @@ from awesomeversion.exceptions import AwesomeVersionCompareException
14
14
 
15
15
  from .const import MAX_AMPS, MIN_AMPS, RAPI_ERRORS, divert_mode
16
16
  from .exceptions import UnknownError, UnsupportedFeature
17
+ from .utils import get_awesome_version
17
18
 
18
19
  _LOGGER = logging.getLogger(__name__)
19
20
 
@@ -357,29 +358,17 @@ class CommandsMixin:
357
358
  """Return the latest firmware version."""
358
359
  if "version" not in self._config:
359
360
  # Throw warning if we can't find the version
360
- _LOGGER.warning("Unable to find firmware version.")
361
+ _LOGGER.debug("Unable to find firmware version.")
361
362
  return None
362
363
  base_url = "https://api.github.com/repos/OpenEVSE/"
363
364
  url = None
364
365
  method = "get"
365
366
 
366
367
  cutoff = AwesomeVersion("3.0.0")
367
- current = ""
368
-
369
368
  _LOGGER.debug("Detected firmware: %s", self._config["version"])
370
369
 
371
- if "dev" in self._config["version"]:
372
- value = self._config["version"]
373
- _LOGGER.debug("Stripping 'dev' from version.")
374
- value = value.split(".")
375
- value = ".".join(value[0:3])
376
- elif "master" in self._config["version"]:
377
- value = "dev"
378
- else:
379
- value = self._config["version"]
380
-
381
- _LOGGER.debug("Using version: %s", value)
382
- current = AwesomeVersion(value)
370
+ current = get_awesome_version(self._config["version"])
371
+ _LOGGER.debug("Using version: %s", current)
383
372
 
384
373
  try:
385
374
  if current >= cutoff:
@@ -387,7 +376,7 @@ class CommandsMixin:
387
376
  else:
388
377
  url = f"{base_url}ESP8266_WiFi_v2.x/releases/latest"
389
378
  except AwesomeVersionCompareException:
390
- _LOGGER.warning("Non-semver firmware version detected.")
379
+ _LOGGER.debug("Non-semver firmware version detected.")
391
380
  return None
392
381
 
393
382
  try:
@@ -492,6 +481,8 @@ class CommandsMixin:
492
481
  _LOGGER.error("Problem issuing command: %s", response)
493
482
  raise UnknownError
494
483
 
484
+ self._status["divertmode"] = new_mode
485
+
495
486
  async def set_shaper(self, enable: bool = True) -> None:
496
487
  """Set shaper mode."""
497
488
  if not self._version_check("4.0.0"):
@@ -500,16 +491,18 @@ class CommandsMixin:
500
491
 
501
492
  url = f"{self.url}shaper"
502
493
  mode = 1 if enable else 0
503
- data = {"mode": mode}
494
+ data = {"shaper": mode}
504
495
 
505
496
  _LOGGER.debug("Setting shaper to %s", mode)
506
- response = await self.process_request(url=url, method="post", data=data)
497
+ response = await self.process_request(url=url, method="post", rapi=data)
507
498
  response = self._normalize_response(response)
508
499
  msg = response.get("msg") if isinstance(response, Mapping) else None
509
500
  if msg not in ["OK", "done", "no change", "Current Shaper state changed"]:
510
501
  _LOGGER.error("Problem issuing command: %s", response)
511
502
  raise UnknownError
512
503
 
504
+ self._status["shaper"] = mode
505
+
513
506
  async def toggle_shaper(self) -> None:
514
507
  """Toggle shaper mode."""
515
508
  shaper_active = self._status.get("shaper")
@@ -9,6 +9,7 @@ from typing import Any
9
9
 
10
10
  from .const import MAX_AMPS, MIN_AMPS, states
11
11
  from .exceptions import UnsupportedFeature
12
+ from .utils import normalize_version
12
13
 
13
14
  _LOGGER = logging.getLogger(__name__)
14
15
 
@@ -130,10 +131,8 @@ class PropertiesMixin:
130
131
  def wifi_firmware(self) -> str | None:
131
132
  """Return the ESP firmware version."""
132
133
  value = self._config.get("version")
133
- if value is not None and "dev" in value:
134
- _LOGGER.debug("Stripping 'dev' from version.")
135
- value = value.split(".")
136
- value = ".".join(value[0:3])
134
+ if value is not None:
135
+ value = normalize_version(value)
137
136
  return value
138
137
 
139
138
  @property
openevsehttp/utils.py ADDED
@@ -0,0 +1,29 @@
1
+ """Utility functions for python-openevse-http."""
2
+
3
+ import logging
4
+ import re
5
+
6
+ from awesomeversion import AwesomeVersion
7
+
8
+ _LOGGER = logging.getLogger(__name__)
9
+
10
+
11
+ def normalize_version(version: str) -> str:
12
+ """Normalize the version string to strip 'dev' tag."""
13
+ if "dev" in version:
14
+ _LOGGER.debug("Stripping 'dev' from version.")
15
+ value = version.split(".")
16
+ return ".".join(value[0:3])
17
+ return version
18
+
19
+
20
+ def get_awesome_version(version: str) -> AwesomeVersion:
21
+ """Parse and normalize the version string, returning an AwesomeVersion."""
22
+ if "master" in version:
23
+ version = "dev"
24
+ value = normalize_version(version)
25
+ if "dev" not in version:
26
+ firmware_search = re.search(r"\d+\.\d+\.\d+", value)
27
+ if firmware_search:
28
+ value = firmware_search.group(0)
29
+ return AwesomeVersion(value)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python_openevse_http
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Python wrapper for OpenEVSE HTTP API
5
5
  Home-page: https://github.com/firstof9/python-openevse-http
6
6
  Download-URL: https://github.com/firstof9/python-openevse-http
@@ -1,15 +1,16 @@
1
1
  openevsehttp/__init__.py,sha256=I6a1mjOZHYiWb_qfCuDuFLOOncrkkB_7uwybtOIujfY,1165
2
2
  openevsehttp/__main__.py,sha256=EHmSdT7GjAVvHQxvLBTjZXsj_V5SB6B2_kpgUAT7mPM,146
3
- openevsehttp/client.py,sha256=rdUZn6HdJgUj5vZDin2PL8DyCBRK5_81YR5XJeGI6B0,18210
4
- openevsehttp/commands.py,sha256=UghodbIq7mF1HDI-o0BpcKcRQm7fgcz_pCqPBOtZPns,21021
3
+ openevsehttp/client.py,sha256=JBAC1jJGdzOabVAqHv8x6EJDVjhaW4t7Iwqn4lDWhwE,17502
4
+ openevsehttp/commands.py,sha256=qro0H2uAzNTIh3LCnP8DgI693J4CKnZkxDRQgWo8HlM,20786
5
5
  openevsehttp/const.py,sha256=VSc5Xt-KFenft0rT6ql9whCD7J9g_YvjLYU_PX706eE,1360
6
6
  openevsehttp/exceptions.py,sha256=bqz-tHTW1AYJMKcm0s5M6z5tA6XZgjnCiBLW1XrZ_70,672
7
7
  openevsehttp/managers.py,sha256=kEX1ZD9u-FY0UEZJsxeFEGBSGzSlkbBc0kmxCiMJtJw,5373
8
- openevsehttp/properties.py,sha256=Lo2p6WfPuhpaEcIZ0OeAxinHSa0G8Sv2wLZ-dPe7rjo,17181
8
+ openevsehttp/properties.py,sha256=QVSyn_5a7vI1b4TdnnToRdw6veVCfnp7a19VYit95hg,17107
9
9
  openevsehttp/sensors.py,sha256=sJP2FPnU1Lk5S3VUyFT14JM1nKEBQPsjl-DiZI-pZrs,4673
10
+ openevsehttp/utils.py,sha256=e3HH_jwZgb1iBWJgIoMOM0JPrQNwXyVdOx5vTWOh4T0,858
10
11
  openevsehttp/websocket.py,sha256=Mi_WFmlT3-9i6bbHIN6ua09SD8CpIle2vRXB3HyWzmM,10066
11
- python_openevse_http-0.3.2.dist-info/licenses/LICENSE,sha256=hSB6TOQ7rmwSGb6XzqRjDGMvmUj5_GlacqQin3tegtA,11341
12
- python_openevse_http-0.3.2.dist-info/METADATA,sha256=owAAfc5N-66JfgL2DjzWeeM94vf3lESDwmFTitwzQQ0,4363
13
- python_openevse_http-0.3.2.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
14
- python_openevse_http-0.3.2.dist-info/top_level.txt,sha256=u8RUkoEIE33Cjn6gmqiEoVpZ0VZ59WJ3FXBwwOg0CPE,13
15
- python_openevse_http-0.3.2.dist-info/RECORD,,
12
+ python_openevse_http-0.3.4.dist-info/licenses/LICENSE,sha256=hSB6TOQ7rmwSGb6XzqRjDGMvmUj5_GlacqQin3tegtA,11341
13
+ python_openevse_http-0.3.4.dist-info/METADATA,sha256=xw9ot2rB-084_Du8lm-9Rx58S0mvOpgb7iEbFb4U6sw,4363
14
+ python_openevse_http-0.3.4.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
15
+ python_openevse_http-0.3.4.dist-info/top_level.txt,sha256=u8RUkoEIE33Cjn6gmqiEoVpZ0VZ59WJ3FXBwwOg0CPE,13
16
+ python_openevse_http-0.3.4.dist-info/RECORD,,