broadlink-async 1.2.0__tar.gz → 1.2.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.
Files changed (45) hide show
  1. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/CHANGELOG.md +12 -0
  2. {broadlink_async-1.2.0/broadlink_async.egg-info → broadlink_async-1.2.1}/PKG-INFO +4 -4
  3. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/README.md +3 -3
  4. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/remote.py +35 -6
  5. {broadlink_async-1.2.0 → broadlink_async-1.2.1/broadlink_async.egg-info}/PKG-INFO +4 -4
  6. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/protocol.md +3 -1
  7. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/pyproject.toml +1 -1
  8. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/test_capture.py +1 -1
  9. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/test_helpers.py +70 -5
  10. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/test_transport.py +10 -2
  11. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/LICENSE +0 -0
  12. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/MANIFEST.in +0 -0
  13. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/TROUBLESHOOTING.md +0 -0
  14. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/__init__.py +0 -0
  15. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/alarm.py +0 -0
  16. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/climate.py +0 -0
  17. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/const.py +0 -0
  18. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/cover.py +0 -0
  19. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/device.py +0 -0
  20. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/exceptions.py +0 -0
  21. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/helpers.py +0 -0
  22. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/hub.py +0 -0
  23. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/light.py +0 -0
  24. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/protocol.py +0 -0
  25. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/sensor.py +0 -0
  26. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async/switch.py +0 -0
  27. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async.egg-info/SOURCES.txt +0 -0
  28. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async.egg-info/dependency_links.txt +0 -0
  29. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async.egg-info/requires.txt +0 -0
  30. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/broadlink_async.egg-info/top_level.txt +0 -0
  31. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/cli/README.md +0 -0
  32. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/cli/broadlink_cli +0 -0
  33. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/cli/broadlink_discovery +0 -0
  34. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/setup.cfg +0 -0
  35. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/__init__.py +0 -0
  36. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/oracle/__init__.py +0 -0
  37. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/oracle/cases.py +0 -0
  38. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/oracle/fixtures.json +0 -0
  39. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/oracle/harness.py +0 -0
  40. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/oracle/record.py +0 -0
  41. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/test_fl_state_rename.py +0 -0
  42. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/test_loopback.py +0 -0
  43. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/test_oracle.py +0 -0
  44. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/test_realign.py +0 -0
  45. {broadlink_async-1.2.0 → broadlink_async-1.2.1}/tests/test_remote.py +0 -0
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project are recorded here. The format follows
4
4
  Keep a Changelog; versions follow Semantic Versioning.
5
5
 
6
+ ## 1.2.1 - 2026-11-04
7
+
8
+ ### Fixed
9
+
10
+ - An IR code built by `pulses_to_data` that ends on a pulse now ends with
11
+ the same 101.5 ms off time as a learned code (`0x00 0x0d 0x05`). Without
12
+ one, an RM4 Pro held the last pulse for up to about 5 ms too long, so
13
+ Philips TVs ignored RC-6 codes from Home Assistant's infrared platform,
14
+ and a code sent with `repeat` ran into its next copy
15
+ (home-assistant/core#190257). Codes that already end on an off time, RF
16
+ codes and learned codes are sent as before.
17
+
6
18
  ## 1.2.0 - 2026-10-20
7
19
 
8
20
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: broadlink-async
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Python API for controlling Broadlink devices
5
5
  Author: DAB-LABS
6
6
  Author-email: Matthew Garrett <mjg59@srcf.ucam.org>
@@ -61,9 +61,9 @@ Every call that reaches a device is a coroutine and must be awaited. That
61
61
  is the main change from the original library's API: method names and
62
62
  arguments are the same, and so are return values, with the small
63
63
  exceptions listed in `CHANGELOG.md` (the IR tick constant, `pulses_to_data`
64
- returning `bytes`, the unused `Device.lock` attribute removed, `timeout`
65
- parameters typed as floats, and the `mac` in a hello response typed as
66
- `bytes`).
64
+ returning `bytes` and ending an IR code that ends on a pulse with an off
65
+ time, the unused `Device.lock` attribute removed, `timeout` parameters
66
+ typed as floats, and the `mac` in a hello response typed as `bytes`).
67
67
 
68
68
  ```python
69
69
  import asyncio
@@ -30,9 +30,9 @@ Every call that reaches a device is a coroutine and must be awaited. That
30
30
  is the main change from the original library's API: method names and
31
31
  arguments are the same, and so are return values, with the small
32
32
  exceptions listed in `CHANGELOG.md` (the IR tick constant, `pulses_to_data`
33
- returning `bytes`, the unused `Device.lock` attribute removed, `timeout`
34
- parameters typed as floats, and the `mac` in a hello response typed as
35
- `bytes`).
33
+ returning `bytes` and ending an IR code that ends on a pulse with an off
34
+ time, the unused `Device.lock` attribute removed, `timeout` parameters
35
+ typed as floats, and the `mac` in a hello response typed as `bytes`).
36
36
 
37
37
  ```python
38
38
  import asyncio
@@ -115,6 +115,27 @@ def rf_carrier_mhz(data: bytes) -> float | None:
115
115
  return khz / 1000 if khz else None
116
116
 
117
117
 
118
+ _IR_TRAILING_GAP_TICKS = 0x0D05
119
+ """Off time, in device ticks, that ends an IR packet whose timings end on a pulse.
120
+
121
+ About 101.5 ms, the value every IR code learned on a Broadlink ends with
122
+ (protocol.md). When an RM4 Pro is sent an IR code whose last timing is a
123
+ pulse, it holds that pulse for up to about 5 ms too long (0.1 to 5.1 ms
124
+ on a bench with firmware 52079, 2026-11-04). That breaks protocols whose
125
+ last half-bit matters, such as RC-6, and runs a repeated code into its
126
+ next copy (home-assistant/core#190257). RF has not been tested for this.
127
+ """
128
+
129
+
130
+ def _append_ticks(result: bytearray, ticks: int) -> None:
131
+ """Append one duration, already in device ticks, to a packet."""
132
+ div, mod = divmod(ticks, 256)
133
+ if div:
134
+ result.append(0)
135
+ result.append(div)
136
+ result.append(mod)
137
+
138
+
118
139
  def pulses_to_data(
119
140
  pulses: list[int],
120
141
  tick: float = TICK,
@@ -127,19 +148,27 @@ def pulses_to_data(
127
148
  ``kind`` selects the type byte (IR, RF 433 MHz or RF 315 MHz) and
128
149
  ``repeat`` is the number of extra transmissions the device performs
129
150
  after the first, 0 to 255 (protocol.md offset 0x01).
151
+
152
+ The durations alternate on, off, starting with on. An IR sequence that
153
+ ends on an on time gets about 101.5 ms of off time after it, as learned
154
+ codes have, so the device ends the last pulse on time. With ``repeat``,
155
+ that off time also separates the copies; for an exact repeat period,
156
+ pass a sequence that ends with your own off time. A sequence that
157
+ already ends on an off time is encoded as given.
130
158
  """
131
159
  if not 0 <= repeat <= 0xFF:
132
160
  raise ValueError("repeat must be between 0 and 255")
161
+ pulses = list(pulses)
162
+ kind = SignalKind(kind)
133
163
  result = bytearray(4)
134
- result[0x00] = SignalKind(kind)
164
+ result[0x00] = kind
135
165
  result[0x01] = repeat
136
166
 
137
167
  for pulse in pulses:
138
- div, mod = divmod(round(pulse / tick), 256)
139
- if div:
140
- result.append(0)
141
- result.append(div)
142
- result.append(mod)
168
+ _append_ticks(result, round(pulse / tick))
169
+
170
+ if kind is SignalKind.IR and len(pulses) % 2:
171
+ _append_ticks(result, _IR_TRAILING_GAP_TICKS)
143
172
 
144
173
  data_len = len(result) - 4
145
174
  result[0x02] = data_len & 0xFF
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: broadlink-async
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Python API for controlling Broadlink devices
5
5
  Author: DAB-LABS
6
6
  Author-email: Matthew Garrett <mjg59@srcf.ucam.org>
@@ -61,9 +61,9 @@ Every call that reaches a device is a coroutine and must be awaited. That
61
61
  is the main change from the original library's API: method names and
62
62
  arguments are the same, and so are return values, with the small
63
63
  exceptions listed in `CHANGELOG.md` (the IR tick constant, `pulses_to_data`
64
- returning `bytes`, the unused `Device.lock` attribute removed, `timeout`
65
- parameters typed as floats, and the `mac` in a hello response typed as
66
- `bytes`).
64
+ returning `bytes` and ending an IR code that ends on a pulse with an off
65
+ time, the unused `Device.lock` attribute removed, `timeout` parameters
66
+ typed as floats, and the `mac` in a hello response typed as `bytes`).
67
67
 
68
68
  ```python
69
69
  import asyncio
@@ -187,7 +187,9 @@ Send the following payload with a command byte of 0x006a
187
187
  Each value is represented by one byte. If the length exceeds one byte
188
188
  then it is stored big endian with a leading 0.
189
189
 
190
- Captures of IR codes from the device will always end with a constant OFF value of `0x00 0x0d 0x05` but the trailing silence can be anything on transmit. The likely reason for this value is a capped timeout value on detection. The value is about 102 milliseconds.
190
+ Captures of IR codes from the device will always end with a constant OFF value of `0x00 0x0d 0x05`. The likely reason for this value is a capped timeout value on detection. The value is about 102 milliseconds.
191
+
192
+ On transmit, an IR code needs an OFF value after its last ON value. When an RM4 Pro is sent an IR code that ends on an ON value, it holds that last pulse for up to about 5 ms too long, and a repeated code runs into its next copy. `pulses_to_data` adds `0x00 0x0d 0x05` to IR codes that end on an ON value.
191
193
 
192
194
  RF codes an RM4 Pro returns from learning use a different layout. Offsets
193
195
  below are within the code itself, so add 4 for the payload above:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "broadlink-async"
7
- version = "1.2.0"
7
+ version = "1.2.1"
8
8
  description = "Python API for controlling Broadlink devices"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -672,7 +672,7 @@ def test_pulses_to_data_rejects_bad_repeat():
672
672
 
673
673
 
674
674
  def test_parse_packet_round_trip():
675
- pulses = [9000, 4500, 560, 1690, 40000]
675
+ pulses = [9000, 4500, 560, 1690, 560, 40000]
676
676
  for kind in SignalKind:
677
677
  packet = pulses_to_data(pulses, kind=kind, repeat=1)
678
678
  parsed = parse_packet(packet)
@@ -8,7 +8,13 @@ import pytest
8
8
 
9
9
  from broadlink_async.helpers import CRC16
10
10
  from broadlink_async.protocol import Datetime
11
- from broadlink_async.remote import TICK, data_to_pulses, pulses_to_data
11
+ from broadlink_async.remote import (
12
+ _IR_TRAILING_GAP_TICKS,
13
+ TICK,
14
+ SignalKind,
15
+ data_to_pulses,
16
+ pulses_to_data,
17
+ )
12
18
 
13
19
 
14
20
  def test_tick_constant():
@@ -33,11 +39,11 @@ def test_pulses_to_data_rounds_to_nearest_tick():
33
39
 
34
40
 
35
41
  def test_pulses_to_data_long_pulse_uses_three_byte_form():
36
- data = pulses_to_data([10000])
42
+ data = pulses_to_data([560, 10000])
37
43
  ticks = round(10000 / TICK) # 328
38
44
  assert ticks > 255
39
- assert data[4:] == bytes([0, ticks >> 8, ticks & 0xFF])
40
- assert int.from_bytes(data[2:4], "little") == 3
45
+ assert data[4:] == bytes([18, 0, ticks >> 8, ticks & 0xFF])
46
+ assert int.from_bytes(data[2:4], "little") == 4
41
47
 
42
48
 
43
49
  def test_explicit_tick_argument_still_honored():
@@ -47,7 +53,7 @@ def test_explicit_tick_argument_still_honored():
47
53
 
48
54
 
49
55
  def test_data_to_pulses_round_trip_at_same_tick():
50
- pulses = [9000, 4500, 560, 560, 560, 1690, 40000]
56
+ pulses = [9000, 4500, 560, 560, 560, 1690, 560, 40000]
51
57
  data = pulses_to_data(pulses)
52
58
  back = data_to_pulses(data)
53
59
  # Rounding on the way in (and int() on the way out) keeps the round
@@ -61,6 +67,65 @@ def test_data_to_pulses_honors_declared_length():
61
67
  assert len(data_to_pulses(data)) == 2
62
68
 
63
69
 
70
+ GAP = bytes([0x00, 0x0D, 0x05]) # _IR_TRAILING_GAP_TICKS, as learned codes end
71
+
72
+
73
+ def test_ir_packet_ending_on_a_mark_gets_the_learned_code_gap():
74
+ # Three durations: on, off, on. The device needs an off time after the
75
+ # last on time (home-assistant/core#190257).
76
+ data = pulses_to_data([328, 656, 328])
77
+ assert _IR_TRAILING_GAP_TICKS == 3333
78
+ assert data[4:] == bytes([11, 22, 11]) + GAP
79
+ assert int.from_bytes(data[2:4], "little") == 6
80
+ assert data_to_pulses(data)[-1] == int(_IR_TRAILING_GAP_TICKS * TICK)
81
+
82
+
83
+ def test_trailing_gap_with_kind_passed_as_an_int():
84
+ assert pulses_to_data([328, 656, 328], kind=0x26).endswith(GAP)
85
+
86
+
87
+ def test_trailing_gap_accepts_any_sequence():
88
+ assert pulses_to_data(iter([328, 656, 328])) == pulses_to_data([328, 656, 328])
89
+
90
+
91
+ def test_empty_ir_packet_gets_no_gap():
92
+ assert pulses_to_data([]) == bytes([0x26, 0, 0, 0])
93
+
94
+
95
+ def test_ir_packet_ending_on_a_space_is_unchanged():
96
+ assert pulses_to_data([328, 656, 328, 656]) == bytes([0x26, 0, 4, 0, 11, 22, 11, 22])
97
+
98
+
99
+ def test_rc6_frame_ends_with_the_gap():
100
+ # Home Assistant's RC-6 encoder ends every frame on a mark: Philips TV
101
+ # power, toggle 1, as infrared-protocols builds it.
102
+ u = 444
103
+ frame = [6 * u, -2 * u, u, -2 * u, u, -u, u, -u, 3 * u, -3 * u]
104
+ frame += [u, -u] * 11 + [2 * u, -u, u, -2 * u, u, -u, u]
105
+ data = pulses_to_data([abs(t) for t in frame])
106
+ assert len(frame) % 2 == 1
107
+ assert data.endswith(GAP)
108
+ assert len(data_to_pulses(data)) == len(frame) + 1
109
+
110
+
111
+ def test_trailing_gap_keeps_the_repeat_byte():
112
+ # A repeated frame needs the gap too, or the next copy's leader runs
113
+ # into the last mark.
114
+ data = pulses_to_data([328, 656, 328], repeat=1)
115
+ assert data[:2] == bytes([0x26, 1])
116
+ assert data.endswith(GAP)
117
+
118
+
119
+ def test_trailing_gap_is_in_device_ticks_whatever_the_tick():
120
+ data = pulses_to_data([328, 656, 328], tick=32.84)
121
+ assert data[4:] == bytes([10, 20, 10]) + GAP
122
+
123
+
124
+ def test_rf_packet_ending_on_a_mark_is_unchanged():
125
+ data = pulses_to_data([328, 656, 328], kind=SignalKind.RF_433)
126
+ assert data == bytes([0xB2, 0, 3, 0, 11, 22, 11])
127
+
128
+
64
129
  def test_data_to_pulses_rejects_truncated_long_form():
65
130
  with pytest.raises(ValueError):
66
131
  data_to_pulses(bytes([0x26, 0x00, 0x02, 0x00, 0x00, 0x01]))
@@ -332,10 +332,14 @@ def test_second_answer_to_a_resent_request_is_not_taken_as_next_reply(net):
332
332
  assert run(go()) == 2
333
333
 
334
334
 
335
- def test_auth_never_lets_a_queued_request_out_with_id_zero(net):
335
+ def test_auth_never_lets_a_queued_request_out_with_id_zero(net, monkeypatch):
336
336
  """A request queued behind the lock while auth() runs must be framed
337
337
  after the new session is installed, never with the initial key and
338
338
  device id 0."""
339
+ # The fake device answers after 2 ms. Keep the resend interval long so a
340
+ # slow runner cannot resend a frame before that answer arrives, which
341
+ # would add a second auth to the exchange this test counts.
342
+ monkeypatch.setattr(device_module, "DEFAULT_RETRY_INTVL", 1.0)
339
343
  dev = fixed_device()
340
344
  dev.id = 5
341
345
  session_key = bytes.fromhex("00112233445566778899aabbccddeeff")
@@ -684,11 +688,15 @@ def test_locked_device_surfaces_as_the_original_error(net):
684
688
  assert types == [0x6A, 0x65, 0x65]
685
689
 
686
690
 
687
- def test_request_queued_behind_an_auth_still_reauths_if_needed(net):
691
+ def test_request_queued_behind_an_auth_still_reauths_if_needed(net, monkeypatch):
688
692
  """The auth generation is read under the lock, so a request that was
689
693
  queued while another caller's auth() ran, and still gets -7, performs
690
694
  its own re-authentication instead of assuming the earlier one covers
691
695
  it."""
696
+ # The fake device answers after 2 ms. Keep the resend interval long so a
697
+ # slow runner cannot resend a frame before that answer arrives, which
698
+ # would add a second auth to the exchange this test counts.
699
+ monkeypatch.setattr(device_module, "DEFAULT_RETRY_INTVL", 1.0)
692
700
  dev = fixed_device()
693
701
  dev.id = 5
694
702
  session_key = bytes.fromhex("00112233445566778899aabbccddeeff")
File without changes