-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'Brand' file to help with brand information (#388)
* Add 'Brand' file to help with brand information * Add tests for missing coverage
- Loading branch information
Showing
8 changed files
with
252 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"""Brand specific information for HomeWizard Energy.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Product: | ||
"""Represent a product.""" | ||
|
||
model: str | ||
name: str | None | ||
url: str | None | ||
description: str | None | ||
|
||
def __str__(self): | ||
"""Return a string representation of the product.""" | ||
return f"HomeWizard {self.name} - {self.model}" | ||
|
||
def __hash__(self): | ||
"""Hash a product for unit-test snapshots.""" | ||
return hash((self.model, self.name, self.url, self.description)) | ||
|
||
def __eq__(self, other): | ||
"""Compare two products.""" | ||
if isinstance(other, Product): | ||
return ( | ||
self.model == other.model | ||
and self.name == other.name | ||
and self.url == other.url | ||
and self.description == other.description | ||
) | ||
return False | ||
|
||
|
||
PRODUCTS = { | ||
Product( | ||
"HWE-P1", | ||
"Wi-Fi P1 Meter", | ||
"https://www.homewizard.com/p1-meter/", | ||
"The HomeWizard P1 Meter gives you detailed insight in your electricity-, gas consumption and solar surplus.", | ||
), | ||
Product( | ||
"HWE-SKT", | ||
"Energy Socket", | ||
"https://www.homewizard.com/energy-socket/", | ||
"Measure and switch every device.", | ||
), | ||
Product( | ||
"HWE-WTR", | ||
"Wi-Fi Watermeter", | ||
"https://www.homewizard.com/watermeter/", | ||
"Real-time water consumption insights", | ||
), | ||
Product( | ||
"HWE-KWH1", | ||
"Wi-Fi kWh meter 1-phase", | ||
"https://www.homewizard.com/kwh-meter/", | ||
"Measure solar panels, car chargers and more.", | ||
), | ||
Product( | ||
"HWE-KWH3", | ||
"Wi-Fi kWh meter 3-phase", | ||
"https://www.homewizard.com/kwh-meter/", | ||
"Measure solar panels, car chargers and more.", | ||
), | ||
Product( | ||
"SDM230-wifi", | ||
"Wi-Fi kWh meter 1-phase", | ||
"https://www.homewizard.com/kwh-meter/", | ||
"Measure solar panels, car chargers and more.", | ||
), | ||
Product( | ||
"SDM630-wifi", | ||
"Wi-Fi kWh meter 3-phase", | ||
"https://www.homewizard.com/kwh-meter/", | ||
"Measure solar panels, car chargers and more.", | ||
), | ||
} | ||
|
||
|
||
def from_type(product_type: str, _: str | None = None) -> Product | None: | ||
"""Return a Product object from a type. | ||
:param type: The type of the product. | ||
:param locale: The locale to use for the description. Currently ignored. Should be an ISO 639-1 language code. | ||
""" | ||
|
||
# pylint: disable=unused-argument | ||
|
||
for product in PRODUCTS: | ||
if product.model == product_type: | ||
return product | ||
return None |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# serializer version: 1 | ||
# name: test_known_product_strings[HWE-KWH1] | ||
'HomeWizard Wi-Fi kWh meter 1-phase - HWE-KWH1' | ||
# --- | ||
# name: test_known_product_strings[HWE-KWH3] | ||
'HomeWizard Wi-Fi kWh meter 3-phase - HWE-KWH3' | ||
# --- | ||
# name: test_known_product_strings[HWE-P1] | ||
'HomeWizard Wi-Fi P1 Meter - HWE-P1' | ||
# --- | ||
# name: test_known_product_strings[HWE-SKT] | ||
'HomeWizard Energy Socket - HWE-SKT' | ||
# --- | ||
# name: test_known_product_strings[HWE-WTR] | ||
'HomeWizard Wi-Fi Watermeter - HWE-WTR' | ||
# --- | ||
# name: test_known_product_strings[SDM230-wifi] | ||
'HomeWizard Wi-Fi kWh meter 1-phase - SDM230-wifi' | ||
# --- | ||
# name: test_known_product_strings[SDM630-wifi] | ||
'HomeWizard Wi-Fi kWh meter 3-phase - SDM630-wifi' | ||
# --- | ||
# name: test_known_products[HWE-KWH1] | ||
Product(model='HWE-KWH1', name='Wi-Fi kWh meter 1-phase', url='https://www.homewizard.com/kwh-meter/', description='Measure solar panels, car chargers and more.') | ||
# --- | ||
# name: test_known_products[HWE-KWH3] | ||
Product(model='HWE-KWH3', name='Wi-Fi kWh meter 3-phase', url='https://www.homewizard.com/kwh-meter/', description='Measure solar panels, car chargers and more.') | ||
# --- | ||
# name: test_known_products[HWE-P1] | ||
Product(model='HWE-P1', name='Wi-Fi P1 Meter', url='https://www.homewizard.com/p1-meter/', description='The HomeWizard P1 Meter gives you detailed insight in your electricity-, gas consumption and solar surplus.') | ||
# --- | ||
# name: test_known_products[HWE-SKT] | ||
Product(model='HWE-SKT', name='Energy Socket', url='https://www.homewizard.com/energy-socket/', description='Measure and switch every device.') | ||
# --- | ||
# name: test_known_products[HWE-WTR] | ||
Product(model='HWE-WTR', name='Wi-Fi Watermeter', url='https://www.homewizard.com/watermeter/', description='Real-time water consumption insights') | ||
# --- | ||
# name: test_known_products[SDM230-wifi] | ||
Product(model='SDM230-wifi', name='Wi-Fi kWh meter 1-phase', url='https://www.homewizard.com/kwh-meter/', description='Measure solar panels, car chargers and more.') | ||
# --- | ||
# name: test_known_products[SDM630-wifi] | ||
Product(model='SDM630-wifi', name='Wi-Fi kWh meter 3-phase', url='https://www.homewizard.com/kwh-meter/', description='Measure solar panels, car chargers and more.') | ||
# --- | ||
# name: test_unknown_or_invalid_products[HWE-P2] | ||
None | ||
# --- | ||
# name: test_unknown_or_invalid_products[None] | ||
None | ||
# --- | ||
# name: test_unknown_or_invalid_products[WTR] | ||
None | ||
# --- | ||
# name: test_unknown_or_invalid_products[] | ||
None | ||
# --- |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"""Test for HomeWizard Energy Models.""" | ||
|
||
import pytest | ||
from syrupy.assertion import SnapshotAssertion | ||
|
||
from homewizard_energy.brand import from_type | ||
|
||
pytestmark = [pytest.mark.asyncio] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("model"), | ||
[ | ||
("HWE-P1"), | ||
("HWE-SKT"), | ||
("HWE-WTR"), | ||
("HWE-KWH1"), | ||
("HWE-KWH3"), | ||
("SDM230-wifi"), | ||
("SDM630-wifi"), | ||
], | ||
) | ||
async def test_known_products(model: str, snapshot: SnapshotAssertion): | ||
"""Test known products.""" | ||
|
||
product = from_type(model) | ||
assert product is not None | ||
assert snapshot == product | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("model"), | ||
[ | ||
("HWE-P1"), | ||
("HWE-SKT"), | ||
("HWE-WTR"), | ||
("HWE-KWH1"), | ||
("HWE-KWH3"), | ||
("SDM230-wifi"), | ||
("SDM630-wifi"), | ||
], | ||
) | ||
async def test_known_product_strings(model: str, snapshot: SnapshotAssertion): | ||
"""Test generating product strings.""" | ||
|
||
product = from_type(model) | ||
assert product is not None | ||
assert snapshot == str(product) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("model"), | ||
[ | ||
("HWE-P2"), | ||
(None), | ||
("WTR"), | ||
(""), | ||
], | ||
) | ||
async def test_unknown_or_invalid_products(model: str, snapshot: SnapshotAssertion): | ||
"""Test unknown or invalid products types.""" | ||
|
||
product = from_type(model) | ||
assert product is None | ||
assert snapshot == product | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("lhs", "rhs", "value"), | ||
[ | ||
("HWE-P1", "HWE-P1", True), | ||
("HWE-P1", "HWE-SKT", False), | ||
("HWE-P1", None, False), | ||
("HWE-P1", "", False), | ||
], | ||
) | ||
async def test_comparison_between_products(lhs: str, rhs: str, value: bool): | ||
"""Test comparison between products.""" | ||
|
||
lhs = from_type(lhs) | ||
rhs = from_type(rhs) | ||
assert (lhs == rhs) == value |