generated from ludeeus/integration_blueprint
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
442 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "mylight_systems" | ||
version = "0.0.6" | ||
version = "0.0.7" | ||
description = "MyLight Systems integration for Home Assistant" | ||
authors = ["Pierre-Emmanuel Mercier <[email protected]>"] | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from custom_components.mylight_systems.api.models import Measure | ||
from custom_components.mylight_systems.coordinator import MyLightSystemsCoordinatorData | ||
from custom_components.mylight_systems.sensor import _calculate_grid_returned_energy | ||
|
||
|
||
def test_calculate_grid_returned_energy_with_none_data_should_return_0(): | ||
# Arrange | ||
data = MyLightSystemsCoordinatorData( | ||
grid_energy=None, | ||
green_energy=None, | ||
produced_energy=None, | ||
grid_energy_without_battery=None, | ||
msb_charge=None, | ||
msb_discharge=None, | ||
self_conso=None, | ||
autonomy_rate=None, | ||
battery_state=None, | ||
) | ||
|
||
# Act | ||
|
||
result = _calculate_grid_returned_energy(data) | ||
|
||
# Assert | ||
|
||
assert result == 0 | ||
|
||
|
||
def test_calculate_grid_returned_energy_with_produced_energy_should_return_produced_energy(): | ||
# Arrange | ||
data = MyLightSystemsCoordinatorData( | ||
grid_energy=None, | ||
green_energy=None, | ||
produced_energy=Measure(key="abcd", value=3600, unit="kwh"), | ||
grid_energy_without_battery=None, | ||
msb_charge=None, | ||
msb_discharge=None, | ||
self_conso=None, | ||
autonomy_rate=None, | ||
battery_state=None, | ||
) | ||
|
||
# Act | ||
|
||
result = _calculate_grid_returned_energy(data) | ||
|
||
# Assert | ||
|
||
assert result == 1.0 | ||
|
||
|
||
def test_calculate_grid_returned_energy_with_produced_and_green_return(): | ||
# Arrange | ||
data = MyLightSystemsCoordinatorData( | ||
grid_energy=None, | ||
green_energy=Measure(key="abcd", value=1800, unit="kwh"), | ||
produced_energy=Measure(key="abcd", value=3600, unit="kwh"), | ||
grid_energy_without_battery=None, | ||
msb_charge=None, | ||
msb_discharge=None, | ||
self_conso=None, | ||
autonomy_rate=None, | ||
battery_state=None, | ||
) | ||
|
||
# Act | ||
|
||
result = _calculate_grid_returned_energy(data) | ||
|
||
# Assert | ||
|
||
assert result == 0.5 | ||
|
||
|
||
def test_calculate_grid_returned_energy_with_produced_and_msb_charge_return(): | ||
# Arrange | ||
data = MyLightSystemsCoordinatorData( | ||
grid_energy=None, | ||
green_energy=None, | ||
produced_energy=Measure(key="abcd", value=3600, unit="kwh"), | ||
grid_energy_without_battery=None, | ||
msb_charge=Measure(key="abcd", value=1800, unit="kwh"), | ||
msb_discharge=None, | ||
self_conso=None, | ||
autonomy_rate=None, | ||
battery_state=None, | ||
) | ||
|
||
# Act | ||
|
||
result = _calculate_grid_returned_energy(data) | ||
|
||
# Assert | ||
|
||
assert result == 0.5 | ||
|
||
def test_calculate_grid_returned_energy_with_all_return(): | ||
# Arrange | ||
data = MyLightSystemsCoordinatorData( | ||
grid_energy=None, | ||
green_energy=Measure(key="abcd", value=800, unit="kwh"), | ||
produced_energy=Measure(key="abcd", value=3600, unit="kwh"), | ||
grid_energy_without_battery=None, | ||
msb_charge=Measure(key="abcd", value=700, unit="kwh"), | ||
msb_discharge=None, | ||
self_conso=None, | ||
autonomy_rate=None, | ||
battery_state=None, | ||
) | ||
|
||
# Act | ||
|
||
result = _calculate_grid_returned_energy(data) | ||
|
||
# Assert | ||
|
||
assert result == 0.59 |