-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add DPT 29 definitions * Common base class for struct usage
- Loading branch information
Showing
10 changed files
with
149 additions
and
44 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,35 @@ | ||
"""Unit test for KNX 8 byte signed objects.""" | ||
|
||
import pytest | ||
|
||
from xknx.dpt import DPT8ByteSigned, DPTArray | ||
from xknx.exceptions import ConversionError | ||
|
||
|
||
class TestDPT8ByteSigned: | ||
"""Test class for KNX 8 byte signed objects.""" | ||
|
||
@pytest.mark.parametrize( | ||
("raw", "expected"), | ||
( | ||
(b"\x00\x00\x00\x00\x00\x00\x00\x00", 0), | ||
(b"\x00\x00\x00\x00\x00\x00\x00\x01", 1), | ||
(b"\x00\x00\x00\x00\x00\x00\x00\xe6", 230), | ||
(b"\xff\xff\xff\xff\xff\xff\xff\x1a", -230), | ||
# limits | ||
(b"\x7f\xff\xff\xff\xff\xff\xff\xff", 9_223_372_036_854_775_807), | ||
(b"\x80\x00\x00\x00\x00\x00\x00\x00", -9_223_372_036_854_775_808), | ||
), | ||
) | ||
def test_values(self, raw, expected): | ||
"""Test valid values.""" | ||
assert DPT8ByteSigned.to_knx(expected) == DPTArray(raw) | ||
assert DPT8ByteSigned.from_knx(DPTArray(raw)) == expected | ||
|
||
@pytest.mark.parametrize( | ||
"value", (9_223_372_036_854_775_808, -9_223_372_036_854_775_809) | ||
) | ||
def test_exceeding_limits(self, value): | ||
"""Test invalid values.""" | ||
with pytest.raises(ConversionError): | ||
DPT8ByteSigned.to_knx(value) |
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
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,52 @@ | ||
"""Implementation of Basic KNX 8-Byte signed (2's complement) values.""" | ||
|
||
from __future__ import annotations | ||
|
||
from .dpt import DPTNumeric, DPTStructIntMixin | ||
|
||
|
||
class DPT8ByteSigned(DPTStructIntMixin, DPTNumeric): | ||
""" | ||
Abstraction for KNX 8 Byte "64-bit signed". | ||
DPT 29.*** | ||
""" | ||
|
||
dpt_main_number = 29 | ||
dpt_sub_number: int | None = None | ||
payload_length = 8 | ||
value_type = "8byte_signed" | ||
|
||
value_min = -9_223_372_036_854_775_808 | ||
value_max = 9_223_372_036_854_775_807 | ||
resolution = 1 | ||
|
||
_struct_format = ">q" | ||
|
||
|
||
class DPTActiveEnergy8Byte(DPT8ByteSigned): | ||
"""DPT 29.010 DPT_Active_Energy_V64.""" | ||
|
||
dpt_main_number = 29 | ||
dpt_sub_number = 10 | ||
value_type = "active_energy_8byte" | ||
unit = "Wh" | ||
ha_device_class = "energy" | ||
|
||
|
||
class DPTApparantEnergy8Byte(DPT8ByteSigned): | ||
"""DPT 29.011 DPT_Apparant_Energy_V64 (VAh).""" | ||
|
||
dpt_main_number = 29 | ||
dpt_sub_number = 11 | ||
value_type = "apparant_energy_8byte" | ||
unit = "VAh" | ||
|
||
|
||
class DPTReactiveEnergy8Byte(DPT8ByteSigned): | ||
"""DPT 29.012 DPT_Reactive_Energy_V64 (VARh).""" | ||
|
||
dpt_main_number = 29 | ||
dpt_sub_number = 12 | ||
value_type = "reactive_energy_8byte" | ||
unit = "VARh" |
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