Skip to content

Commit

Permalink
fix: Fixed where intelligent entities were incorrectly available to u…
Browse files Browse the repository at this point in the history
…sers on intelligent flux tariff
  • Loading branch information
BottlecapDave committed Jan 5, 2024
1 parent c43ef73 commit 0be466a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion custom_components/octopus_energy/intelligent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def mock_intelligent_device():
def is_intelligent_tariff(tariff_code: str):
parts = get_tariff_parts(tariff_code.upper())

return parts is not None and "INTELLI" in parts.product_code
# Need to ignore Octopus Intelligent Go tariffs
return parts is not None and ("INTELLI-BB-VAR" in parts.product_code or "INTELLI-VAR" in parts.product_code)

def has_intelligent_tariff(current: datetime, account_info):
if account_info is not None and len(account_info["electricity_meter_points"]) > 0:
Expand Down
15 changes: 12 additions & 3 deletions tests/unit/intelligent/test_is_intelligent_tariff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@

@pytest.mark.asyncio
@pytest.mark.parametrize("tariff_code",[
("E-1R-INTELLI-VAR-22-10-14-C"),
("E-1R-INTELLI-VAR-22-10-14-C".upper()),
("E-1R-INTELLI-VAR-22-10-14-C".lower()),
("E-1R-INTELLI-BB-VAR-23-03-01-C".upper()),
("E-1R-INTELLI-BB-VAR-23-03-01-C".lower()),
])
async def test_when_tariff_code_is_valid_then_true_returned(tariff_code: str):
# Act
assert is_intelligent_tariff(tariff_code.upper()) == True
assert is_intelligent_tariff(tariff_code.lower()) == True

@pytest.mark.asyncio
async def test_when_invalid_then_none_returned():
@pytest.mark.parametrize("tariff_code",[
("invalid-tariff-code".upper()),
("invalid-tariff-code".lower()),
("E-1R-INTELLI-FLUX-IMPORT-23-07-14-E".upper()),
("E-1R-INTELLI-FLUX-IMPORT-23-07-14-E".lower()),
])
async def test_when_invalid_then_none_returned(tariff_code):
# Act
assert is_intelligent_tariff("invalid-tariff-code") == False
assert is_intelligent_tariff(tariff_code) == False

0 comments on commit 0be466a

Please sign in to comment.