-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Convert the ZLinky_TIC quirk to v2 and expose tariff period sensors #5245
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
Open
yoda-jm
wants to merge
5
commits into
zigpy:dev
Choose a base branch
from
yoda-jm:zlinky-tariff-entities
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51e0eed
Convert the ZLinky_TIC quirk to v2
4896d7f
Expose ZLinky_TIC tariff period and meter status sensors
f886c0e
Keep removing the Tuya cluster the ZLinky_TIC does not implement
08d789c
Record why the v1 subclasses collapse and the allow list entries go
024a7fc
Exercise both Tuya cluster removal directions in the test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,70 @@ | ||
| """Tests for LiXee ZLinky_TIC quirks.""" | ||
|
|
||
| from zha.quirks import DEVICE_REGISTRY | ||
| from zigpy.zcl.clusters.general import PowerConfiguration | ||
| from zigpy.zcl.clusters.smartenergy import Metering | ||
|
|
||
| import zhaquirks | ||
| from zhaquirks.builder.device import QuirkV2Factory | ||
| from zhaquirks.lixee import LIXEE, ZLINKY_MANUFACTURER_CLUSTER_ID | ||
| from zhaquirks.lixee.zlinky import ZLinkyTICManufacturerCluster, ZLinkyTICMetering | ||
|
|
||
| zhaquirks.setup() | ||
|
|
||
|
|
||
| def _zlinky_definition(): | ||
| """Return the QuirkDefinition registered for the ZLinky_TIC.""" | ||
| (entry,) = [ | ||
| entry | ||
| for entry in DEVICE_REGISTRY | ||
| if isinstance(entry.zha_device_factory, QuirkV2Factory) | ||
| and any( | ||
| model_info.manufacturer == LIXEE and model_info.model == "ZLinky_TIC" | ||
| for model_info in entry.device_match.applies_to | ||
| ) | ||
| ] | ||
| return entry.zha_device_factory.quirk_definition | ||
|
|
||
|
|
||
| def test_zlinky_clusters_replaced(zigpy_device_from_v2_quirk) -> None: | ||
| """Test that the ZLinky_TIC quirk replaces the expected clusters.""" | ||
| device = zigpy_device_from_v2_quirk( | ||
| LIXEE, | ||
| "ZLinky_TIC", | ||
| cluster_ids={ | ||
| 1: { | ||
| Metering.cluster_id: None, | ||
| ZLINKY_MANUFACTURER_CLUSTER_ID: None, | ||
| } | ||
| }, | ||
| ) | ||
| endpoint = device.endpoints[1] | ||
|
|
||
| assert isinstance(endpoint.smartenergy_metering, ZLinkyTICMetering) | ||
| assert isinstance( | ||
| endpoint.zlinky_manufacturer_specific, ZLinkyTICManufacturerCluster | ||
| ) | ||
| # Not all firmware variants report it, the quirk adds it unconditionally | ||
| assert PowerConfiguration.cluster_id in endpoint.in_clusters | ||
|
|
||
|
|
||
| def test_zlinky_tariff_entities() -> None: | ||
| """Test that the tariff and diagnostic sensors are exposed.""" | ||
| attribute_defs = ZLinkyTICManufacturerCluster.AttributeDefs | ||
| definition = _zlinky_definition() | ||
|
|
||
| assert { | ||
| entity_metadata.attribute_name for entity_metadata in definition.entity_metadata | ||
| } == { | ||
| attribute_defs.linky_tariff_period.name, | ||
| attribute_defs.hist_tariff_option_or_std_supplier_price_schedule_name.name, | ||
| attribute_defs.hist_subscribed_power_exceeding_warning.name, | ||
| attribute_defs.hist_schedule_peak_hours_off_peak_hours.name, | ||
| attribute_defs.linky_status.name, | ||
| attribute_defs.linky_mode.name, | ||
| } | ||
|
|
||
| # Every entity reads from the manufacturer specific cluster on endpoint 1 | ||
| for entity_metadata in definition.entity_metadata: | ||
| assert entity_metadata.cluster_id == ZLINKY_MANUFACTURER_CLUSTER_ID | ||
| assert entity_metadata.endpoint_id == 1 |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.