rf-protocols 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rf_protocols-0.0.1/LICENSE +21 -0
- rf_protocols-0.0.1/PKG-INFO +19 -0
- rf_protocols-0.0.1/README.md +3 -0
- rf_protocols-0.0.1/pyproject.toml +46 -0
- rf_protocols-0.0.1/rf_protocols/__init__.py +10 -0
- rf_protocols-0.0.1/rf_protocols/commands.py +80 -0
- rf_protocols-0.0.1/rf_protocols.egg-info/PKG-INFO +19 -0
- rf_protocols-0.0.1/rf_protocols.egg-info/SOURCES.txt +11 -0
- rf_protocols-0.0.1/rf_protocols.egg-info/dependency_links.txt +1 -0
- rf_protocols-0.0.1/rf_protocols.egg-info/requires.txt +4 -0
- rf_protocols-0.0.1/rf_protocols.egg-info/top_level.txt +1 -0
- rf_protocols-0.0.1/setup.cfg +4 -0
- rf_protocols-0.0.1/tests/test_commands.py +114 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Home Assistant Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rf-protocols
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Library to decode and encode radio frequency signals.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/home-assistant-libs/rf-protocols
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.13.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest; extra == "dev"
|
|
14
|
+
Requires-Dist: prek; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Python RF Protocols for Home Assistant
|
|
18
|
+
|
|
19
|
+
Python package to decode and encode radio frequency signals for use in Home Assistant.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=78.1.1,<83.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rf-protocols"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
description = "Library to decode and encode radio frequency signals."
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
]
|
|
15
|
+
requires-python = ">=3.13.0"
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
"Homepage" = "https://github.com/home-assistant-libs/rf-protocols"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools]
|
|
21
|
+
include-package-data = false
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
include = ["rf_protocols*"]
|
|
25
|
+
|
|
26
|
+
[tool.ruff.lint]
|
|
27
|
+
select = [
|
|
28
|
+
# pycodestyle
|
|
29
|
+
"E",
|
|
30
|
+
# Pyflakes
|
|
31
|
+
"F",
|
|
32
|
+
# pyupgrade
|
|
33
|
+
"UP",
|
|
34
|
+
# flake8-bugbear
|
|
35
|
+
"B",
|
|
36
|
+
# isort
|
|
37
|
+
"I",]
|
|
38
|
+
|
|
39
|
+
[tool.ruff.lint.mccabe]
|
|
40
|
+
max-complexity = 25
|
|
41
|
+
|
|
42
|
+
[tool.pyright]
|
|
43
|
+
typeCheckingMode = "standard"
|
|
44
|
+
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
dev = ["pytest", "prek"]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Common RF command definitions."""
|
|
2
|
+
|
|
3
|
+
import abc
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from enum import StrEnum
|
|
6
|
+
from typing import override
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ModulationType(StrEnum):
|
|
10
|
+
"""RF modulation type."""
|
|
11
|
+
|
|
12
|
+
OOK = "OOK"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True, slots=True)
|
|
16
|
+
class Timing:
|
|
17
|
+
"""High/low signal timing for OOK modulation."""
|
|
18
|
+
|
|
19
|
+
high_us: int
|
|
20
|
+
low_us: int
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class RadioFrequencyCommand(abc.ABC):
|
|
24
|
+
"""Base class for RF commands."""
|
|
25
|
+
|
|
26
|
+
frequency: int
|
|
27
|
+
repeat_count: int
|
|
28
|
+
modulation: ModulationType
|
|
29
|
+
symbol_rate: int | None
|
|
30
|
+
output_power: float | None
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
*,
|
|
35
|
+
frequency: int,
|
|
36
|
+
modulation: ModulationType,
|
|
37
|
+
repeat_count: int = 0,
|
|
38
|
+
symbol_rate: int | None = None,
|
|
39
|
+
output_power: float | None = None,
|
|
40
|
+
) -> None:
|
|
41
|
+
"""Initialize the RF command."""
|
|
42
|
+
self.frequency = frequency
|
|
43
|
+
self.modulation = modulation
|
|
44
|
+
self.repeat_count = repeat_count
|
|
45
|
+
self.symbol_rate = symbol_rate
|
|
46
|
+
self.output_power = output_power
|
|
47
|
+
|
|
48
|
+
@abc.abstractmethod
|
|
49
|
+
def get_raw_timings(self) -> list[Timing]:
|
|
50
|
+
"""Get raw timings for OOK commands."""
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class OOKCommand(RadioFrequencyCommand):
|
|
54
|
+
"""OOK command with raw timings."""
|
|
55
|
+
|
|
56
|
+
timings: list[Timing]
|
|
57
|
+
|
|
58
|
+
def __init__(
|
|
59
|
+
self,
|
|
60
|
+
*,
|
|
61
|
+
frequency: int,
|
|
62
|
+
timings: list[Timing],
|
|
63
|
+
repeat_count: int = 0,
|
|
64
|
+
symbol_rate: int | None = None,
|
|
65
|
+
output_power: float | None = None,
|
|
66
|
+
) -> None:
|
|
67
|
+
"""Initialize the OOK command."""
|
|
68
|
+
super().__init__(
|
|
69
|
+
frequency=frequency,
|
|
70
|
+
modulation=ModulationType.OOK,
|
|
71
|
+
repeat_count=repeat_count,
|
|
72
|
+
symbol_rate=symbol_rate,
|
|
73
|
+
output_power=output_power,
|
|
74
|
+
)
|
|
75
|
+
self.timings = timings
|
|
76
|
+
|
|
77
|
+
@override
|
|
78
|
+
def get_raw_timings(self) -> list[Timing]:
|
|
79
|
+
"""Get raw timings."""
|
|
80
|
+
return self.timings
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rf-protocols
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Library to decode and encode radio frequency signals.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/home-assistant-libs/rf-protocols
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.13.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest; extra == "dev"
|
|
14
|
+
Requires-Dist: prek; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# Python RF Protocols for Home Assistant
|
|
18
|
+
|
|
19
|
+
Python package to decode and encode radio frequency signals for use in Home Assistant.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
rf_protocols/__init__.py
|
|
5
|
+
rf_protocols/commands.py
|
|
6
|
+
rf_protocols.egg-info/PKG-INFO
|
|
7
|
+
rf_protocols.egg-info/SOURCES.txt
|
|
8
|
+
rf_protocols.egg-info/dependency_links.txt
|
|
9
|
+
rf_protocols.egg-info/requires.txt
|
|
10
|
+
rf_protocols.egg-info/top_level.txt
|
|
11
|
+
tests/test_commands.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rf_protocols
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Tests for the RF protocol definitions."""
|
|
2
|
+
|
|
3
|
+
from rf_protocols import ModulationType, OOKCommand, RadioFrequencyCommand, Timing
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_modulation_type_ook() -> None:
|
|
7
|
+
"""Test ModulationType enum has OOK value."""
|
|
8
|
+
assert ModulationType.OOK == "OOK"
|
|
9
|
+
assert ModulationType.OOK.value == "OOK"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_timing_frozen() -> None:
|
|
13
|
+
"""Test Timing is a frozen dataclass."""
|
|
14
|
+
timing = Timing(high_us=350, low_us=1050)
|
|
15
|
+
assert timing.high_us == 350
|
|
16
|
+
assert timing.low_us == 1050
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_timing_equality() -> None:
|
|
20
|
+
"""Test Timing equality comparison."""
|
|
21
|
+
assert Timing(high_us=350, low_us=1050) == Timing(high_us=350, low_us=1050)
|
|
22
|
+
assert Timing(high_us=350, low_us=1050) != Timing(high_us=350, low_us=350)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _MockCommand(RadioFrequencyCommand):
|
|
26
|
+
"""Simple concrete command for testing the base class."""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
*,
|
|
31
|
+
frequency: int = 433_920_000,
|
|
32
|
+
modulation: ModulationType = ModulationType.OOK,
|
|
33
|
+
repeat_count: int = 0,
|
|
34
|
+
symbol_rate: int | None = None,
|
|
35
|
+
output_power: float | None = None,
|
|
36
|
+
) -> None:
|
|
37
|
+
super().__init__(
|
|
38
|
+
frequency=frequency,
|
|
39
|
+
modulation=modulation,
|
|
40
|
+
repeat_count=repeat_count,
|
|
41
|
+
symbol_rate=symbol_rate,
|
|
42
|
+
output_power=output_power,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def get_raw_timings(self) -> list[Timing]:
|
|
46
|
+
"""Return a simple test pattern."""
|
|
47
|
+
return [Timing(high_us=350, low_us=1050), Timing(high_us=350, low_us=350)]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_command_defaults() -> None:
|
|
51
|
+
"""Test RadioFrequencyCommand default values."""
|
|
52
|
+
cmd = _MockCommand()
|
|
53
|
+
assert cmd.frequency == 433_920_000
|
|
54
|
+
assert cmd.repeat_count == 0
|
|
55
|
+
assert cmd.modulation == ModulationType.OOK
|
|
56
|
+
assert cmd.symbol_rate is None
|
|
57
|
+
assert cmd.output_power is None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_command_custom_values() -> None:
|
|
61
|
+
"""Test RadioFrequencyCommand with custom values."""
|
|
62
|
+
cmd = _MockCommand(
|
|
63
|
+
frequency=868_000_000,
|
|
64
|
+
repeat_count=3,
|
|
65
|
+
symbol_rate=4800,
|
|
66
|
+
output_power=10.0,
|
|
67
|
+
)
|
|
68
|
+
assert cmd.frequency == 868_000_000
|
|
69
|
+
assert cmd.repeat_count == 3
|
|
70
|
+
assert cmd.modulation == ModulationType.OOK
|
|
71
|
+
assert cmd.symbol_rate == 4800
|
|
72
|
+
assert cmd.output_power == 10.0
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_command_get_raw_timings() -> None:
|
|
76
|
+
"""Test get_raw_timings returns expected timings."""
|
|
77
|
+
cmd = _MockCommand()
|
|
78
|
+
timings = cmd.get_raw_timings()
|
|
79
|
+
assert timings == [
|
|
80
|
+
Timing(high_us=350, low_us=1050),
|
|
81
|
+
Timing(high_us=350, low_us=350),
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_ook_command() -> None:
|
|
86
|
+
"""Test OOKCommand with raw timings."""
|
|
87
|
+
timings = [
|
|
88
|
+
Timing(high_us=350, low_us=1050),
|
|
89
|
+
Timing(high_us=350, low_us=350),
|
|
90
|
+
Timing(high_us=350, low_us=0),
|
|
91
|
+
]
|
|
92
|
+
cmd = OOKCommand(frequency=433_920_000, timings=timings)
|
|
93
|
+
assert cmd.frequency == 433_920_000
|
|
94
|
+
assert cmd.modulation == ModulationType.OOK
|
|
95
|
+
assert cmd.repeat_count == 0
|
|
96
|
+
assert cmd.get_raw_timings() == timings
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_ook_command_custom_values() -> None:
|
|
100
|
+
"""Test OOKCommand with custom radio parameters."""
|
|
101
|
+
timings = [Timing(high_us=500, low_us=1000)]
|
|
102
|
+
cmd = OOKCommand(
|
|
103
|
+
frequency=868_000_000,
|
|
104
|
+
timings=timings,
|
|
105
|
+
repeat_count=2,
|
|
106
|
+
symbol_rate=4800,
|
|
107
|
+
output_power=10.0,
|
|
108
|
+
)
|
|
109
|
+
assert cmd.frequency == 868_000_000
|
|
110
|
+
assert cmd.modulation == ModulationType.OOK
|
|
111
|
+
assert cmd.repeat_count == 2
|
|
112
|
+
assert cmd.symbol_rate == 4800
|
|
113
|
+
assert cmd.output_power == 10.0
|
|
114
|
+
assert cmd.get_raw_timings() == timings
|