python-openevse-http 1.0.2__tar.gz → 1.4.0__tar.gz

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.
Files changed (74) hide show
  1. python_openevse_http-1.4.0/.github/ISSUE_TEMPLATE/bug_report.yml +62 -0
  2. python_openevse_http-1.4.0/.github/ISSUE_TEMPLATE/config.yml +5 -0
  3. python_openevse_http-1.4.0/.github/ISSUE_TEMPLATE/feature_request.yml +25 -0
  4. python_openevse_http-1.4.0/.github/pull_request_template.md +26 -0
  5. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/PKG-INFO +30 -1
  6. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/README.md +29 -0
  7. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/example_external_session.py +18 -0
  8. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/client.py +9 -1
  9. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/commands.py +2 -0
  10. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/const.py +2 -0
  11. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/sensors.py +38 -1
  12. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/utils.py +3 -1
  13. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/websocket.py +10 -2
  14. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/python_openevse_http.egg-info/PKG-INFO +30 -1
  15. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/python_openevse_http.egg-info/SOURCES.txt +4 -0
  16. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/requirements_lint.txt +2 -2
  17. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/requirements_test.txt +2 -2
  18. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_client.py +58 -1
  19. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_sensors.py +38 -0
  20. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_websocket.py +52 -0
  21. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.github/dependabot.yml +0 -0
  22. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.github/release-drafter.yml +0 -0
  23. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.github/workflows/autolabeler.yml +0 -0
  24. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.github/workflows/links.yml +0 -0
  25. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.github/workflows/publish-to-pypi.yml +0 -0
  26. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.github/workflows/release-drafter.yml +0 -0
  27. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.github/workflows/test.yml +0 -0
  28. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.gitignore +0 -0
  29. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.pre-commit-config.yaml +0 -0
  30. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/.yamllint +0 -0
  31. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/EXTERNAL_SESSION.md +0 -0
  32. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/LICENSE +0 -0
  33. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/codecov.yml +0 -0
  34. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/__init__.py +0 -0
  35. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/__main__.py +0 -0
  36. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/exceptions.py +0 -0
  37. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/managers.py +0 -0
  38. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/properties.py +0 -0
  39. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/openevsehttp/py.typed +0 -0
  40. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/pyproject.toml +0 -0
  41. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/python_openevse_http.egg-info/dependency_links.txt +0 -0
  42. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/python_openevse_http.egg-info/not-zip-safe +0 -0
  43. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/python_openevse_http.egg-info/requires.txt +0 -0
  44. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/python_openevse_http.egg-info/top_level.txt +0 -0
  45. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/requirements.txt +0 -0
  46. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/setup.cfg +0 -0
  47. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/setup.py +0 -0
  48. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/__init__.py +0 -0
  49. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/common.py +0 -0
  50. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/conftest.py +0 -0
  51. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/github_v2.json +0 -0
  52. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/github_v4.json +0 -0
  53. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v2_json/config.json +0 -0
  54. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v2_json/status.json +0 -0
  55. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/config-broken-semver.json +0 -0
  56. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/config-broken.json +0 -0
  57. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/config-dev.json +0 -0
  58. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/config-extra-version.json +0 -0
  59. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/config-new.json +0 -0
  60. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/config-unknown-semver.json +0 -0
  61. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/config.json +0 -0
  62. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/schedule.json +0 -0
  63. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/status-broken.json +0 -0
  64. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/status-new.json +0 -0
  65. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/v4_json/status.json +0 -0
  66. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/fixtures/websocket.json +0 -0
  67. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_commands.py +0 -0
  68. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_external_session.py +0 -0
  69. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_main_edge_cases.py +0 -0
  70. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_managers.py +0 -0
  71. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_mixins.py +0 -0
  72. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_properties.py +0 -0
  73. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tests/test_shaper.py +0 -0
  74. {python_openevse_http-1.0.2 → python_openevse_http-1.4.0}/tox.ini +0 -0
@@ -0,0 +1,62 @@
1
+ name: 🐛 Bug Report
2
+ labels: ["bug"]
3
+ title: "[Bug]: "
4
+ description: Report a bug in python-openevse-http.
5
+ body:
6
+ - type: textarea
7
+ validations:
8
+ required: true
9
+ attributes:
10
+ label: Describe the bug
11
+ description: A clear and concise description of what the bug is. Tell us what you were trying to do and what happened.
12
+ placeholder: E.g., calling OpenEVSE.update() raises an exception.
13
+ - type: textarea
14
+ validations:
15
+ required: true
16
+ attributes:
17
+ label: Steps to reproduce
18
+ description: Steps to reproduce the behavior.
19
+ placeholder: |
20
+ 1. Initialize OpenEVSE with ...
21
+ 2. Call ...
22
+ 3. See error
23
+ - type: textarea
24
+ validations:
25
+ required: true
26
+ attributes:
27
+ label: Expected behavior
28
+ description: A clear and concise description of what you expected to happen.
29
+ - type: markdown
30
+ attributes:
31
+ value: |
32
+ ## Environment Info
33
+ - type: input
34
+ id: version
35
+ validations:
36
+ required: true
37
+ attributes:
38
+ label: Library version
39
+ placeholder: e.g., 1.0.0, main branch
40
+ - type: input
41
+ id: python_version
42
+ validations:
43
+ required: true
44
+ attributes:
45
+ label: Python version
46
+ placeholder: e.g., 3.10, 3.11
47
+ - type: input
48
+ id: firmware_version
49
+ validations:
50
+ required: false
51
+ attributes:
52
+ label: OpenEVSE WiFi Firmware version
53
+ placeholder: e.g., 4.1.2, 5.0.0
54
+ - type: textarea
55
+ attributes:
56
+ label: Debug Logs / Stack Trace
57
+ description: Please paste any relevant traceback outputs or logs here (enable debug logging if possible).
58
+ render: txt
59
+ - type: textarea
60
+ attributes:
61
+ label: Additional context
62
+ description: Add any other context or screenshots about the bug here.
@@ -0,0 +1,5 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: Ask a question / Support Request
4
+ url: https://github.com/firstof9/python-openevse-http/discussions
5
+ about: Please ask questions and get support on GitHub Discussions.
@@ -0,0 +1,25 @@
1
+ name: ✨ Feature Request
2
+ labels: ["feature"]
3
+ title: "[Feature Request]: "
4
+ description: Request a feature for python-openevse-http.
5
+ body:
6
+ - type: textarea
7
+ validations:
8
+ required: true
9
+ attributes:
10
+ label: Is your feature request related to a problem? Please describe.
11
+ description: A clear and concise description of what the problem is. E.g. I'm always frustrated when [...]
12
+ - type: textarea
13
+ validations:
14
+ required: true
15
+ attributes:
16
+ label: Describe the solution you'd like
17
+ description: A clear and concise description of what you want to happen.
18
+ - type: textarea
19
+ attributes:
20
+ label: Describe alternatives you've considered
21
+ description: A clear and concise description of any alternative solutions or features you've considered.
22
+ - type: textarea
23
+ attributes:
24
+ label: Additional context
25
+ description: Add any other context or screenshots about the feature request here.
@@ -0,0 +1,26 @@
1
+ ## Description
2
+
3
+ Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
4
+
5
+ Fixes # (issue)
6
+
7
+ ## Type of change
8
+
9
+ Please delete options that are not relevant.
10
+
11
+ - [ ] Bug fix (non-breaking change which fixes an issue)
12
+ - [ ] New feature (non-breaking change which adds functionality)
13
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14
+ - [ ] Code quality / Refactoring
15
+ - [ ] Documentation update
16
+
17
+ ## Checklist
18
+
19
+ - [ ] My code follows the style guidelines of this project
20
+ - [ ] I have performed a self-review of my own code
21
+ - [ ] I have commented my code, particularly in hard-to-understand areas
22
+ - [ ] I have made corresponding changes to the documentation
23
+ - [ ] My changes generate no new warnings
24
+ - [ ] I have added tests that prove my fix is effective or that my feature works
25
+ - [ ] New and existing unit tests pass locally with my changes
26
+ - [ ] Any dependent changes have been merged and published in downstream modules
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python_openevse_http
3
- Version: 1.0.2
3
+ Version: 1.4.0
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
@@ -84,6 +84,35 @@ async def main():
84
84
  if __name__ == "__main__":
85
85
  asyncio.run(main())
86
86
  ```
87
+ ### HTTPS and SSL Verification Options
88
+
89
+ If your OpenEVSE WiFi/ethernet module uses HTTPS, you can configure the client to connect securely using the `ssl=True` parameter:
90
+
91
+ ```python
92
+ # Connect securely using HTTPS (validating SSL/TLS certificates)
93
+ charger = OpenEVSE(
94
+ "192.168.1.30",
95
+ session=session,
96
+ ssl=True,
97
+ )
98
+ ```
99
+
100
+ #### Bypassing SSL Verification (Self-Signed Certificates)
101
+
102
+ > [!WARNING]
103
+ > Disabling SSL certificate validation (`ssl_verify=False`) disables TLS verification and exposes the connection to Man-in-the-Middle (MITM) attacks. Only use this configuration when connecting to an OpenEVSE module with a self-signed certificate over a trusted local network.
104
+
105
+ To bypass certificate verification:
106
+
107
+ ```python
108
+ # Connect using HTTPS, and disable certificate verification
109
+ charger = OpenEVSE(
110
+ "192.168.1.30",
111
+ session=session,
112
+ ssl=True,
113
+ ssl_verify=False,
114
+ )
115
+ ```
87
116
 
88
117
  ## API Support Matrix
89
118
 
@@ -51,6 +51,35 @@ async def main():
51
51
  if __name__ == "__main__":
52
52
  asyncio.run(main())
53
53
  ```
54
+ ### HTTPS and SSL Verification Options
55
+
56
+ If your OpenEVSE WiFi/ethernet module uses HTTPS, you can configure the client to connect securely using the `ssl=True` parameter:
57
+
58
+ ```python
59
+ # Connect securely using HTTPS (validating SSL/TLS certificates)
60
+ charger = OpenEVSE(
61
+ "192.168.1.30",
62
+ session=session,
63
+ ssl=True,
64
+ )
65
+ ```
66
+
67
+ #### Bypassing SSL Verification (Self-Signed Certificates)
68
+
69
+ > [!WARNING]
70
+ > Disabling SSL certificate validation (`ssl_verify=False`) disables TLS verification and exposes the connection to Man-in-the-Middle (MITM) attacks. Only use this configuration when connecting to an OpenEVSE module with a self-signed certificate over a trusted local network.
71
+
72
+ To bypass certificate verification:
73
+
74
+ ```python
75
+ # Connect using HTTPS, and disable certificate verification
76
+ charger = OpenEVSE(
77
+ "192.168.1.30",
78
+ session=session,
79
+ ssl=True,
80
+ ssl_verify=False,
81
+ )
82
+ ```
54
83
 
55
84
  ## API Support Matrix
56
85
 
@@ -49,6 +49,24 @@ async def example_shared_session():
49
49
  await charger2.ws_disconnect()
50
50
 
51
51
 
52
+ async def example_with_https_and_ssl_bypass():
53
+ """Demonstrate using HTTPS with bypassed SSL verification."""
54
+ async with aiohttp.ClientSession() as session:
55
+ # Pass ssl=True to construct an https:// URL,
56
+ # and ssl_verify=False to bypass certificate validation.
57
+ charger = OpenEVSE(
58
+ "192.168.1.30",
59
+ session=session,
60
+ ssl=True,
61
+ ssl_verify=False,
62
+ )
63
+
64
+ # Use the charger normally
65
+ await charger.update()
66
+ print(f"Status: {charger.status}")
67
+ await charger.ws_disconnect()
68
+
69
+
52
70
  if __name__ == "__main__":
53
71
  # Run one of the examples
54
72
  asyncio.run(example_with_external_session())
@@ -53,11 +53,16 @@ class OpenEVSE(CommandsMixin, ManagersMixin, SensorsMixin, PropertiesMixin):
53
53
  user: str | None = None,
54
54
  pwd: str | None = None,
55
55
  session: aiohttp.ClientSession | None = None,
56
+ ssl: bool = False,
57
+ ssl_verify: bool = True,
56
58
  ) -> None:
57
59
  """Connect to an OpenEVSE charger equipped with wifi or ethernet."""
58
60
  self._user = user or ""
59
61
  self._pwd = pwd or ""
60
- self.url = f"http://{host}/"
62
+ self.ssl = ssl
63
+ self.ssl_verify = ssl_verify
64
+ scheme = "https" if ssl else "http"
65
+ self.url = f"{scheme}://{host}/"
61
66
  self._status: dict[str, Any] = {}
62
67
  self._config: dict[str, Any] = {}
63
68
  self._override: Any = None
@@ -134,6 +139,8 @@ class OpenEVSE(CommandsMixin, ManagersMixin, SensorsMixin, PropertiesMixin):
134
139
  kwargs = {"data": rapi, "auth": auth}
135
140
  if data is not None:
136
141
  kwargs["json"] = data
142
+ if url.startswith("https://") and not self.ssl_verify:
143
+ kwargs["ssl"] = False
137
144
  async with http_method(url, **kwargs) as resp:
138
145
  try:
139
146
  raw = await resp.text()
@@ -285,6 +292,7 @@ class OpenEVSE(CommandsMixin, ManagersMixin, SensorsMixin, PropertiesMixin):
285
292
  self._user,
286
293
  self._pwd,
287
294
  self._session,
295
+ ssl_verify=self.ssl_verify,
288
296
  )
289
297
 
290
298
  def _validate_session_loop(self, loop: asyncio.AbstractEventLoop) -> None:
@@ -23,6 +23,8 @@ class CommandsMixin:
23
23
  """Mixin providing command methods for OpenEVSE."""
24
24
 
25
25
  url: str
26
+ ssl: bool
27
+ ssl_verify: bool
26
28
  _status: dict[str, Any]
27
29
  _config: dict[str, Any]
28
30
  _session: aiohttp.ClientSession | None
@@ -23,6 +23,8 @@ BAT_RANGE = "battery_range"
23
23
  TTF = "time_to_full_charge"
24
24
  VOLTAGE = "voltage"
25
25
  SHAPER_LIVE = "shaper_live_pwr"
26
+ HOME_BATTERY_SOC = "home_battery_soc"
27
+ HOME_BATTERY_POWER = "home_battery_power"
26
28
  TYPE = "type"
27
29
  VALUE = "value"
28
30
  RELEASE = "release"
@@ -6,7 +6,16 @@ import logging
6
6
  from collections.abc import Mapping
7
7
  from typing import Any
8
8
 
9
- from .const import BAT_LVL, BAT_RANGE, GRID, SOLAR, TTF, VOLTAGE
9
+ from .const import (
10
+ BAT_LVL,
11
+ BAT_RANGE,
12
+ GRID,
13
+ HOME_BATTERY_POWER,
14
+ HOME_BATTERY_SOC,
15
+ SOLAR,
16
+ TTF,
17
+ VOLTAGE,
18
+ )
10
19
  from .exceptions import UnsupportedFeature
11
20
 
12
21
  _LOGGER = logging.getLogger(__name__)
@@ -122,6 +131,34 @@ class SensorsMixin:
122
131
  response = await self.process_request(url=url, method="post", data=data)
123
132
  _LOGGER.debug("SOC response: %s", self._normalize_response(response))
124
133
 
134
+ # Home/powerwall battery HTTP Posting
135
+ async def home_battery(
136
+ self,
137
+ soc: int | None = None,
138
+ power: int | None = None,
139
+ ) -> None:
140
+ """Send pushed home/powerwall battery data to the charger."""
141
+ if not self._version_check("4.1.0"):
142
+ _LOGGER.debug("Feature not supported for older firmware.")
143
+ raise UnsupportedFeature
144
+
145
+ url = f"{self.url}status"
146
+ data = {}
147
+
148
+ if soc is not None:
149
+ data[HOME_BATTERY_SOC] = soc
150
+ if power is not None:
151
+ data[HOME_BATTERY_POWER] = power
152
+
153
+ if not data:
154
+ _LOGGER.info("No home battery data to send to device.")
155
+ else:
156
+ _LOGGER.debug("Posting home battery data: %s", data)
157
+ response = await self.process_request(url=url, method="post", data=data)
158
+ _LOGGER.debug(
159
+ "Home battery response: %s", self._normalize_response(response)
160
+ )
161
+
125
162
  # Shaper HTTP Posting
126
163
  async def set_shaper_live_pwr(self, power: int) -> None:
127
164
  """Send pushed sensor data to shaper."""
@@ -32,7 +32,9 @@ def get_awesome_version(version: str) -> AwesomeVersion:
32
32
  # We use custom word boundary checks to avoid false positives like 'domain' matching 'main'
33
33
  # or 'webmaster' matching 'master'.
34
34
  is_dev = False
35
- if re.search(
35
+ if re.search(r"_modified$", version, re.IGNORECASE):
36
+ is_dev = True
37
+ elif re.search(
36
38
  r"(?:^|[^a-zA-Z0-9])(master|main)(?:[^a-zA-Z0-9]|$)", version, re.IGNORECASE
37
39
  ):
38
40
  is_dev = True
@@ -42,9 +42,11 @@ class OpenEVSEWebsocket:
42
42
  user: str | None = None,
43
43
  password: str | None = None,
44
44
  session: aiohttp.ClientSession | None = None,
45
+ ssl_verify: bool = True,
45
46
  ) -> None:
46
47
  """Initialize a OpenEVSEWebsocket instance."""
47
48
  self.session = session
49
+ self.ssl_verify = ssl_verify
48
50
  self.uri = self._get_uri(server)
49
51
  self._user = user
50
52
  self._password = password
@@ -133,10 +135,16 @@ class OpenEVSEWebsocket:
133
135
  try:
134
136
  # Narrow type for mypy since _ensure_session sets self.session
135
137
  assert self.session is not None
138
+ ws_kwargs: dict[str, Any] = {
139
+ "heartbeat": 15,
140
+ "auth": auth,
141
+ }
142
+ if self.uri.startswith("wss://") and not self.ssl_verify:
143
+ ws_kwargs["ssl"] = False
144
+
136
145
  async with self.session.ws_connect(
137
146
  self.uri,
138
- heartbeat=15,
139
- auth=auth,
147
+ **ws_kwargs,
140
148
  ) as ws_client:
141
149
  self._client = ws_client
142
150
  await self._set_state(STATE_CONNECTED)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python_openevse_http
3
- Version: 1.0.2
3
+ Version: 1.4.0
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
@@ -84,6 +84,35 @@ async def main():
84
84
  if __name__ == "__main__":
85
85
  asyncio.run(main())
86
86
  ```
87
+ ### HTTPS and SSL Verification Options
88
+
89
+ If your OpenEVSE WiFi/ethernet module uses HTTPS, you can configure the client to connect securely using the `ssl=True` parameter:
90
+
91
+ ```python
92
+ # Connect securely using HTTPS (validating SSL/TLS certificates)
93
+ charger = OpenEVSE(
94
+ "192.168.1.30",
95
+ session=session,
96
+ ssl=True,
97
+ )
98
+ ```
99
+
100
+ #### Bypassing SSL Verification (Self-Signed Certificates)
101
+
102
+ > [!WARNING]
103
+ > Disabling SSL certificate validation (`ssl_verify=False`) disables TLS verification and exposes the connection to Man-in-the-Middle (MITM) attacks. Only use this configuration when connecting to an OpenEVSE module with a self-signed certificate over a trusted local network.
104
+
105
+ To bypass certificate verification:
106
+
107
+ ```python
108
+ # Connect using HTTPS, and disable certificate verification
109
+ charger = OpenEVSE(
110
+ "192.168.1.30",
111
+ session=session,
112
+ ssl=True,
113
+ ssl_verify=False,
114
+ )
115
+ ```
87
116
 
88
117
  ## API Support Matrix
89
118
 
@@ -13,7 +13,11 @@ requirements_test.txt
13
13
  setup.py
14
14
  tox.ini
15
15
  .github/dependabot.yml
16
+ .github/pull_request_template.md
16
17
  .github/release-drafter.yml
18
+ .github/ISSUE_TEMPLATE/bug_report.yml
19
+ .github/ISSUE_TEMPLATE/config.yml
20
+ .github/ISSUE_TEMPLATE/feature_request.yml
17
21
  .github/workflows/autolabeler.yml
18
22
  .github/workflows/links.yml
19
23
  .github/workflows/publish-to-pypi.yml
@@ -1,4 +1,4 @@
1
1
  -r requirements.txt
2
- prek==0.4.4
3
- ruff==0.15.16
2
+ prek==0.4.5
3
+ ruff==0.15.17
4
4
  mypy==2.1.0
@@ -1,6 +1,6 @@
1
1
  -r requirements.txt
2
- prek==0.4.4
3
- pytest==9.0.3
2
+ prek==0.4.5
3
+ pytest==9.1.0
4
4
  pytest-cov==7.1.0
5
5
  pytest-timeout==2.4.0
6
6
  pytest-asyncio
@@ -671,14 +671,30 @@ async def test_version_check_dev_branches():
671
671
  charger._config = {"version": "feature_1A2B3C"}
672
672
  assert charger._version_check("2.0.0") is True
673
673
 
674
+ # Suffix matching for _modified - treated as dev, returns True
675
+ charger._config = {
676
+ "version": "local_feature/gui-nightshift-default_2bcdf1d0_modified"
677
+ }
678
+ assert charger._version_check("2.0.0") is True
679
+
680
+ charger._config = {"version": "custom_branch/my-feature_abc123_modified"}
681
+ assert charger._version_check("2.0.0") is True
682
+
683
+ charger._config = {"version": "main_modified"}
684
+ assert charger._version_check("2.0.0") is True
685
+
674
686
  # False positives containing 'main' or 'master' but not at word boundaries,
675
- # or ending in 6-char hashes without dev keywords should fail version check
687
+ # ending in 6-char hashes without dev keywords, or other non-matching modified strings
688
+ # — should fail version check
676
689
  charger._config = {"version": "domain_abc123"}
677
690
  assert charger._version_check("2.0.0") is False
678
691
 
679
692
  charger._config = {"version": "webmaster_def456"}
680
693
  assert charger._version_check("2.0.0") is False
681
694
 
695
+ charger._config = {"version": "unmodified"}
696
+ assert charger._version_check("2.0.0") is False
697
+
682
698
  # Pre-release (rc) version — should fail when checking against a newer target
683
699
  charger._config = {"version": "4.1.2_rc1"}
684
700
  assert charger._version_check("5.0.0") is False
@@ -1871,3 +1887,44 @@ async def test_get_session_no_running_loop_mocked(charger_factory):
1871
1887
  charger = charger_factory()
1872
1888
  with patch("asyncio.get_running_loop", side_effect=RuntimeError):
1873
1889
  assert charger._get_session() is charger._session
1890
+
1891
+
1892
+ async def test_ssl_options(mock_aioclient):
1893
+ """Test SSL options and SSL verification configuration."""
1894
+ # 1. Default (ssl=False, ssl_verify=True)
1895
+ charger_default = OpenEVSE(SERVER_URL, session=MockClientSession(mock_aioclient))
1896
+ assert charger_default.url == f"http://{SERVER_URL}/"
1897
+ assert charger_default.ssl is False
1898
+ assert charger_default.ssl_verify is True
1899
+
1900
+ # 2. Secure connection (ssl=True, ssl_verify=True)
1901
+ charger_ssl = OpenEVSE(
1902
+ SERVER_URL, ssl=True, session=MockClientSession(mock_aioclient)
1903
+ )
1904
+ assert charger_ssl.url == f"https://{SERVER_URL}/"
1905
+ assert charger_ssl.ssl is True
1906
+ assert charger_ssl.ssl_verify is True
1907
+
1908
+ # 3. Secure connection with disabled validation (ssl=True, ssl_verify=False)
1909
+ charger_no_verify = OpenEVSE(
1910
+ SERVER_URL,
1911
+ ssl=True,
1912
+ ssl_verify=False,
1913
+ session=MockClientSession(mock_aioclient),
1914
+ )
1915
+ assert charger_no_verify.url == f"https://{SERVER_URL}/"
1916
+ assert charger_no_verify.ssl is True
1917
+ assert charger_no_verify.ssl_verify is False
1918
+
1919
+ # Check request parameter passing
1920
+ url = f"https://{SERVER_URL}/status"
1921
+ mock_aioclient.get(url, status=200, body='{"state": "sleeping"}')
1922
+
1923
+ # When ssl_verify=False, ssl=False should be passed to session request kwargs
1924
+ await charger_no_verify.process_request(url, method="get")
1925
+ assert mock_aioclient.requests[-1][2].get("ssl") is False
1926
+
1927
+ # When ssl_verify=True, ssl should NOT be passed as False
1928
+ mock_aioclient.get(url, status=200, body='{"state": "sleeping"}')
1929
+ await charger_ssl.process_request(url, method="get")
1930
+ assert "ssl" not in mock_aioclient.requests[-1][2]
@@ -88,6 +88,44 @@ async def test_soc(test_charger, test_charger_v2, mock_aioclient, caplog):
88
88
  await test_charger_v2.ws_disconnect()
89
89
 
90
90
 
91
+ # ── home_battery ─────────────────────────────────────────────────────
92
+
93
+
94
+ async def test_home_battery(test_charger, test_charger_v2, mock_aioclient, caplog):
95
+ """Test home_battery function."""
96
+ await test_charger.update()
97
+ mock_aioclient.post(
98
+ TEST_URL_STATUS,
99
+ status=200,
100
+ body='{"home_battery_soc": 82, "home_battery_power": -1500}',
101
+ repeat=True,
102
+ )
103
+ with caplog.at_level(logging.DEBUG):
104
+ await test_charger.home_battery(82, -1500)
105
+ assert (
106
+ "Posting home battery data: {'home_battery_soc': 82, 'home_battery_power': -1500}"
107
+ in caplog.text
108
+ )
109
+ assert (
110
+ "Home battery response: {'home_battery_soc': 82, 'home_battery_power': -1500}"
111
+ in caplog.text
112
+ )
113
+
114
+ await test_charger.home_battery(soc=50)
115
+ assert "Posting home battery data: {'home_battery_soc': 50}" in caplog.text
116
+
117
+ await test_charger.home_battery()
118
+ assert "No home battery data to send to device." in caplog.text
119
+ await test_charger.ws_disconnect()
120
+
121
+ await test_charger_v2.update()
122
+ with pytest.raises(UnsupportedFeature):
123
+ with caplog.at_level(logging.DEBUG):
124
+ await test_charger_v2.home_battery(50, -100)
125
+ assert "Feature not supported for older firmware." in caplog.text
126
+ await test_charger_v2.ws_disconnect()
127
+
128
+
91
129
  # ── voltage ──────────────────────────────────────────────────────────
92
130
 
93
131
 
@@ -548,3 +548,55 @@ async def test_websocket_close_cancels_pending_tasks(ws_client):
548
548
  # Close should cancel and drain tasks
549
549
  await ws_client.close()
550
550
  assert len(ws_client._tasks) == 0
551
+
552
+
553
+ @pytest.mark.asyncio
554
+ async def test_websocket_ssl_options(mock_callback):
555
+ """Test OpenEVSEWebsocket SSL options and ws_connect parameter passing."""
556
+ async with aiohttp.ClientSession() as session:
557
+ # Default ssl_verify=True
558
+ ws_default = OpenEVSEWebsocket(
559
+ "https://openevse.test.tld/",
560
+ mock_callback,
561
+ session=session,
562
+ )
563
+ assert ws_default.ssl_verify is True
564
+ assert ws_default.uri == "wss://openevse.test.tld/ws"
565
+
566
+ # Explicit ssl_verify=False
567
+ ws_no_verify = OpenEVSEWebsocket(
568
+ "https://openevse.test.tld/",
569
+ mock_callback,
570
+ session=session,
571
+ ssl_verify=False,
572
+ )
573
+ assert ws_no_verify.ssl_verify is False
574
+ assert ws_no_verify.uri == "wss://openevse.test.tld/ws"
575
+
576
+ # Mock ws_connect to check that it is called with ssl=False when ssl_verify=False
577
+ mock_ws = AsyncMock()
578
+ mock_ws.__aenter__ = AsyncMock(return_value=mock_ws)
579
+ mock_ws.__aexit__ = AsyncMock(return_value=None)
580
+
581
+ async def empty_iter():
582
+ return
583
+ yield
584
+
585
+ mock_ws.__aiter__.side_effect = empty_iter
586
+
587
+ with patch(
588
+ "aiohttp.ClientSession.ws_connect", return_value=mock_ws
589
+ ) as mock_connect:
590
+ await ws_no_verify.running()
591
+ mock_connect.assert_called_once()
592
+ call_kwargs = mock_connect.call_args.kwargs
593
+ assert call_kwargs.get("ssl") is False
594
+
595
+ # When ssl_verify=True, ws_connect should NOT pass ssl=False
596
+ with patch(
597
+ "aiohttp.ClientSession.ws_connect", return_value=mock_ws
598
+ ) as mock_connect:
599
+ await ws_default.running()
600
+ mock_connect.assert_called_once()
601
+ call_kwargs = mock_connect.call_args.kwargs
602
+ assert "ssl" not in call_kwargs