Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Set operation mode and Backup percentage #46

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
daniel-simpson committed Mar 21, 2023
commit 0c5eefdb58b70999dc8fe479e118cbac212ed2e9
27 changes: 27 additions & 0 deletions tests/integration/test_powerwall.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
SiteInfo,
SiteMaster,
)
from tesla_powerwall.const import OperationMode
from tesla_powerwall.responses import PowerwallStatus
from tests.integration import POWERWALL_IP, POWERWALL_PASSWORD

@@ -99,6 +100,32 @@ def test_status(self) -> None:
status.start_time
status.version

def test_setOperationModeAndBackupPercent(self) -> None:
# Get initial values
initial_operation_mode = self.powerwall.get_operation_mode()
self.assertIsInstance(initial_operation_mode, OperationMode)
initial_backup_reserve_percentage = self.powerwall.get_backup_reserve_percentage()
self.assertIsInstance(initial_backup_reserve_percentage, float)

# Arrange
expected_operation_mode = OperationMode.SELF_CONSUMPTION
expected_backup_reserve_percentage = 80

# Act
self.powerwall.set_operation_mode(expected_operation_mode)
self.powerwall.set_backup_reserve_percentage(expected_backup_reserve_percentage)
observed_operation_mode = self.powerwall.get_operation_mode()
observed_backup_reserve_percentage = self.powerwall.get_backup_reserve_percentage()

# Assert
self.assertEqual(observed_operation_mode, expected_operation_mode)
self.assertEqual(observed_backup_reserve_percentage, expected_backup_reserve_percentage)

# Reset back to initial values
self.powerwall.set_operation_mode(initial_operation_mode)
self.powerwall.set_backup_reserve_percentage(initial_backup_reserve_percentage)


def test_islanding(self) -> None:
initial_grid_status = self.powerwall.get_grid_status()
self.assertIsInstance(initial_grid_status, GridStatus)
18 changes: 18 additions & 0 deletions tests/unit/test_powerwall.py
Original file line number Diff line number Diff line change
@@ -197,6 +197,15 @@ def test_get_backup_reserved_percentage(self):
self.powerwall.get_backup_reserve_percentage(), 5.000019999999999
)

@responses.activate
def test_set_backup_reserve_percentage(self):
add(
Response(responses.POST, url=f"{ENDPOINT}operation", json=OPERATION_RESPONSE)
)
self.assertEqual(
self.powerwall.set_backup_reserve_percentage(5.000019999999999), 5.000019999999999
)

@responses.activate
def test_get_operation_mode(self):
add(
@@ -206,6 +215,15 @@ def test_get_operation_mode(self):
self.powerwall.get_operation_mode(), OperationMode.SELF_CONSUMPTION
)

@responses.activate
def test_set_operation_mode(self):
add(
Response(responses.POST, url=f"{ENDPOINT}operation", json=OPERATION_RESPONSE)
)
self.assertEqual(
self.powerwall.set_operation_mode(OperationMode.SELF_CONSUMPTION), OperationMode.SELF_CONSUMPTION
)

@responses.activate
def test_get_version(self):
add(Response(responses.GET, url=f"{ENDPOINT}status", json=STATUS_RESPONSE))