Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Calibration is essential for accurate position tracking. The integration measure

You can calibrate a blind:
- **During initial pairing**: After naming your device, you'll be prompted to calibrate
- **Later from the device page**: Go to the device and click the **Calibrate** gear icon (⚙️) as shown below
- **After pairing from the device page**: Go to the device and click the **Calibrate** gear icon (⚙️) as shown below

![Calibrate button location](images/calibrate-button.png)

Expand Down
20 changes: 14 additions & 6 deletions custom_components/schellenberg_usb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from __future__ import annotations

import asyncio
from collections.abc import Callable
import logging
from collections.abc import Callable

import serial_asyncio

from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_send

Expand Down Expand Up @@ -348,9 +347,13 @@ async def pair_device_and_wait(self) -> tuple[str, str] | None:
# Get the next available device enumerator
device_enum = self.initialize_next_device_enum()

# Format: ssXX9400000
# XX = device enumerator, 94 = pair command, 00000 = padding
pair_command = f"{CMD_TRANSMIT}{device_enum}{CMD_PAIR}00000"
# Format: ssXX9CCPPPP
# ss = transmit prefix
# XX = device enumerator (2 hex chars)
# 9 = number of messages to send
# CC = command (60 = pair)
# PPPP = padding (4 chars)
pair_command = f"{CMD_TRANSMIT}{device_enum}9{CMD_PAIR}0000"

_LOGGER.info(
"Initiating pairing with device enum %s. Command: %s",
Expand All @@ -362,15 +365,20 @@ async def pair_device_and_wait(self) -> tuple[str, str] | None:
self._pairing_future = self.hass.loop.create_future()

try:
# Send sp command to enter pairing/listening mode (like C# does)
_LOGGER.debug("Entering pairing mode with command: sp")
await self.send_command(CMD_GET_PARAM_P)

# Wait for device to send its ID first (with timeout)
device_id = await asyncio.wait_for(
self._pairing_future, timeout=PAIRING_TIMEOUT
)

# Once we have the device ID, send the pairing command
_LOGGER.debug(
"Received device ID %s, sending pairing command",
"Received device ID %s, sending pairing command: %s",
device_id,
pair_command,
)
await self.send_command(pair_command)
except TimeoutError:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test = [
"polyfactory~=3.1.0",
"PyYAML~=6.0.2",
# Need specific versions
"pytest-homeassistant-custom-component==0.13.297",
"pytest-homeassistant-custom-component==0.13.299",
# Versions handled by pytest-homeassistant-custom-component
"freezegun",
"pytest",
Expand All @@ -29,7 +29,7 @@ test = [
]

lint = [
"mypy~=1.18.2",
"mypy~=1.19.0",
"pre-commit~=4.5.0",
"ruff~=0.14.1",
"types-PyYAML~=6.0.12.20250915",
Expand Down
Loading
Loading