Skip to content

Commit

Permalink
feat: add self_production function
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 committed Jul 26, 2023
1 parent f7c9d03 commit 2b85655
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions openevsehttp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,25 @@ def _version_check(self, min_version: str, max_version: str = "") -> bool:
_LOGGER.debug("Non-semver firmware version detected.")
return False

# Self production HTTP Posting

async def self_production(self, grid: int, solar: int, invert: bool = True) -> None:
"""Send pushed sensor data to self-prodcution."""
if not self._version_check("4.0.0"):
_LOGGER.debug("Feature not supported for older firmware.")
raise UnsupportedFeature

Check warning on line 590 in openevsehttp/__main__.py

View check run for this annotation

Codecov / codecov/patch

openevsehttp/__main__.py#L588-L590

Added lines #L588 - L590 were not covered by tests

# Invert the sensor -import/+export
if invert:
grid = grid * -1

Check warning on line 594 in openevsehttp/__main__.py

View check run for this annotation

Codecov / codecov/patch

openevsehttp/__main__.py#L593-L594

Added lines #L593 - L594 were not covered by tests

url = f"{self.url}status"
data = {"solar": solar, "grid": grid}

Check warning on line 597 in openevsehttp/__main__.py

View check run for this annotation

Codecov / codecov/patch

openevsehttp/__main__.py#L596-L597

Added lines #L596 - L597 were not covered by tests

_LOGGER.debug("Posting self-production: %s", data)
response = await self.process_request(url=url, method="post", data=data)
_LOGGER.debug("Self-production response: %s", response)

Check warning on line 601 in openevsehttp/__main__.py

View check run for this annotation

Codecov / codecov/patch

openevsehttp/__main__.py#L599-L601

Added lines #L599 - L601 were not covered by tests

@property
def hostname(self) -> str:
"""Return charger hostname."""
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ commands =
mypy openevsehttp
deps =
-rrequirements_lint.txt

[flake8]
max-line-length = 88

0 comments on commit 2b85655

Please sign in to comment.