API reference
aiorainpoint
RainPoint API module.
Re-exports the client, the push client, the per-model decoders, the catalog
lookups and the helpers callers need, so they import all of them from one
place. Model identifiers and the model table live in the models namespace.
SINGLE_OUTLET_GALLONS_PER_COUNT
module-attribute
SINGLE_OUTLET_GALLONS_PER_COUNT = _FLOW_LITRES_PER_COUNT / _LITRES_PER_US_GALLON
USAGE_GALLONS_PER_COUNT
module-attribute
USAGE_GALLONS_PER_COUNT = 1 / 500
decode_flowmeter
module-attribute
decode_flowmeter = decode_flow_meter
UNCODED_VARIANT
module-attribute
UNCODED_VARIANT = '*'
RainPointApiError
Bases: RainPointError
A call failed at the API level, such as a non-200 status or a non-zero response code.
RainPointClient
RainPointClient(area_code: str, email: str, password: str, session: ClientSession, *, app_code: int = 2)
The RainPoint cloud API client every read and write in this integration goes through.
Holds the account credentials and the session token, refreshes the token on demand, and exposes one method per cloud endpoint the client uses.
Bind a client to one account, over a caller-supplied aiohttp session.
app_code selects the vendor app the account belongs to: 2 for RainPoint, 1 for HomGar.
register_relogin_listener
register_relogin_listener(callback: Callable[[], None]) -> None
Register a callback fired synchronously after a re-login rotates the token.
Not fired on the initial login of a session -- only when the token is replaced while a previous token was already held.
register_token_invalidated_listener
register_token_invalidated_listener(callback: Callable[[], None]) -> None
Register a callback fired synchronously when a rejection expires the cached token.
Its purpose is to let the caller persist the now-known-dead expiry, so a later rebuild of the client (e.g. after a re-authentication) does not replay it. Does not fire when the rejection predicate declines to act.
restore_tokens
restore_tokens(data: Mapping[str, Any]) -> None
Restore tokens from a dict shaped like export_tokens() output.
export_tokens
export_tokens() -> dict
Export token state; callers that persist the tokens store them under these keys.
ensure_logged_in
async
ensure_logged_in() -> None
Log in unless the token is valid; raise RainPointThrottledError, with no network call, during a server cooldown.
list_homes
async
list_homes() -> list[dict]
Return the account's homes as raw cloud records.
get_product_catalog
async
get_product_catalog() -> list[dict]
Fetch the product catalog over this client's session; see fetch_product_catalog.
get_devices_by_hid
async
get_devices_by_hid(hid: int) -> list[dict]
Return one home's hub records, each carrying its subDevices; hid is the id list_homes reports.
get_hub_firmware_info
async
get_hub_firmware_info(mid: int) -> dict
Return one hub's firmware check result: {"info": ..., "softVer": ...}.
"softVer" is the installed version and is the same string the device record carries, so a caller that wants both versions needs this call alone and no cross-reference against the poll snapshot.
get_sub_firmware_info
async
get_sub_firmware_info(sid: int) -> dict
Return one sub-device's firmware check result, same shape as the hub's.
A different endpoint and a different addressing scheme -- sid, the
same one update_sub_param writes against, not the addr the control
paths use -- but the envelope is byte for byte what the hub check
returns, confirmed against an HTV245FRF, an HCS026FRF and an HTV210B on
2026-08-25. That is what lets both share the decode below and the one
base class above them.
Answered for all three of those models even though the RainPoint app offers a "check for updates" link on the HTV210B alone, so this is not gated on a model list.
get_multiple_device_status
async
get_multiple_device_status(devices: list[dict]) -> list[dict]
Get status for multiple devices in one API call (more efficient).
get_device_status
async
get_device_status(mid: int) -> dict
Get status for a single device by MID.
get_subscribe_status
async
get_subscribe_status(device_name: str, product_key: str, mid: int, hid) -> dict
Fetch fresh per-session MQTT observer credentials from subscribeStatus.
device_name/product_key/mid identify the hub (sourced from the hub record, not a second login call); hid is the home the hub belongs to. The server requires the full subscribe envelope -- hid, hidList, a subscribe device list (which must carry the mid), and userInfo -- and rejects a bare {deviceName, productKey} with code 9999 "must not be null". The response carries deviceSecret; it must never be logged in the clear.
update_main_param
async
update_main_param(mid: int, param: str) -> bool
Write a hub's top-level param blob back to the cloud.
param is the same pipe-delimited string the poll reads off the hub
record, spliced by the caller so only the field it understands
changes. Code 0 is the only success verdict; there is no code-4
idempotent branch here as there is on control_work_mode -- code 4 is
that endpoint's already-in-state signal, never observed on this one,
and inventing the branch would ship an untested success path.
update_sub_param
async
update_sub_param(mid, sid, param: str) -> bool
Write a sub-device's param blob back to the cloud, addressed by sid.
param is the comma-separated key=value string the poll reads off the
sub-device record, spliced by the caller (never rebuilt here) so only
the key it understands changes, mirroring update_main_param's
contract for the sibling hub blob. mid and sid reach the request
body unchanged, without coercion: the capture that confirmed this
endpoint showed the app sending mid as a string and sid as an int,
while the sibling main/update endpoint accepts the integer mid
this integration already sends elsewhere -- inventing a conversion
either way would be an untested assumption. Code 0 is the only
success verdict; there is no code-4 idempotent branch, matching
update_main_param -- code 4 has never been observed on this
endpoint either, and inventing the branch would ship an untested
success path.
control_work_mode
async
control_work_mode(mid: int, addr: int, device_name: str, product_key: str, port: int, mode: int, duration: int | None = None) -> str | None
Open or close a valve zone on a hub sub-device, or address the hub itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mid
|
int
|
Hub device ID. |
required |
addr
|
int
|
Sub-device address (e.g. 1 for the first RF valve, 0 for the hub itself). |
required |
device_name
|
str
|
Hub deviceName (MAC-based identifier). |
required |
product_key
|
str
|
Hub productKey. |
required |
port
|
int
|
Zone/port number (1-based). |
required |
mode
|
int
|
1 = open, 0 = close. |
required |
duration
|
int | None
|
Run time for the call, in whatever unit the addressed device family reads it: seconds for the RF valves, minutes for the HIC801W irrigation controller, which answered a request for 2 with a run it reported as 120 seconds. This method sends the int as-is and converts nothing, so choosing the unit belongs to the caller that knows the family. Pass 0 on a close, since the device ignores this field on close commands but it must still be present in the request. Pass None (the default) to omit the "duration" key from the payload entirely, which is what a hub-addressed call (addr=0) needs: the app sends no duration field there, and there is no evidence an omission and an explicit 0 are equivalent at that address. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
The value of |
str | None
|
|
str | None
|
if neither condition produces a value (including when the dict response |
str | None
|
omits the "state" key). Callers should treat None as "no optimistic |
str | None
|
update available" rather than an error. Also returns normally |
str | None
|
(without raising) when the API returns code 4 (device already in |
str | None
|
the requested state); callers cannot distinguish this from a |
str | None
|
code-0 success based on the return value alone. |
control_work_mode_dp
async
control_work_mode_dp(mid: int, addr: int, device_name: str, product_key: str, port: int, mode: int, param: str, dp_code: int = _DP_CODE_CTL_BT_WATER) -> str | None
Open or close a Bluetooth-backed valve zone over the datapoint control endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mid
|
int
|
Hub device ID. |
required |
addr
|
int
|
Sub-device address. |
required |
device_name
|
str
|
Hub deviceName (MAC-based identifier). |
required |
product_key
|
str
|
Hub productKey. |
required |
port
|
int
|
Zone/port number (1-based). |
required |
mode
|
int
|
1 = open, 0 = close. |
required |
param
|
str
|
The pre-encoded 4-byte little-endian hex duration string this
endpoint reads in place of a |
required |
dp_code
|
int
|
The datapoint this command addresses. Defaults to the Bluetooth valve code every current caller wants, so the valve path reads the same as it did before this became settable. An override must be a code the committed catalog declares for the device being addressed, never an arbitrary integer. |
_DP_CODE_CTL_BT_WATER
|
Returns:
| Type | Description |
|---|---|
str | None
|
The value of |
str | None
|
|
str | None
|
if neither condition produces a value (including when the dict |
str | None
|
response omits the "state" key). Callers should treat None as "no |
str | None
|
optimistic update available" rather than an error. Also returns |
str | None
|
normally (without raising) when the API returns code 4 (device |
str | None
|
already in the requested state); callers cannot distinguish this |
str | None
|
from a code-0 success based on the return value alone. |
RainPointError
Bases: Exception
Base for the errors the client raises itself; aiohttp transport errors propagate unwrapped.
RainPointThrottledError
RainPointThrottledError(message: str, retry_after: float)
Bases: RainPointApiError
Login is refused because the server is throttling us, not because the credentials are wrong.
Carries retry_after (seconds) so callers can surface a "please wait"
message or back off, instead of treating it as an authentication failure.
Subclasses RainPointApiError so existing handlers keep working.
retry_after
instance-attribute
retry_after = retry_after
RainPointMqttClient
RainPointMqttClient(loop: AbstractEventLoop, client: RainPointClient, hub_device_name: str, hub_product_key: str, *, coordinator: PushCoordinator | None = None, hub_mid=None, hub_hid=None, paho_client_factory=paho_mqtt.Client, time_source=time.monotonic, wall_clock_source=time.time, executor_job: Callable[[Callable[[], None]], Awaitable[None]] | None = None)
Supervised push channel to the RainPoint MQTT broker.
One owned asyncio.Task (_run_supervisor) connects, renews credentials before their expiry via a clean disconnect-old/reconnect-new cycle, and retries indefinitely under jittered backoff on any failure. It never SUBSCRIBEs -- the broker pushes downlink messages to the connected device unsolicited. paho's own auto-reconnect is disabled so the supervisor is the sole reconnect authority.
Build the client for one hub's observer credentials.
The hub arguments name whose credentials open the session, not whose traffic it carries: the session is account-scoped and every frame is routed by the mid it names. The three factory and clock arguments are test seams, and the two clocks are deliberately separate, one monotonic for renewal bookkeeping and one wall-clock for the protocol timestamp.
message_count
property
message_count: int
Return the running count of messages received since connect (test/diagnostic seam).
hub_mid
property
hub_mid
Return the mid of the hub whose credentials opened this session (or None).
Not the mid of any frame's sender, and not a bound on what this client reports for: _dispatch_push routes every frame on the mid the frame itself names, so one session serves every hub on the account. This is the construction identity, needed for the subscribeStatus envelope and the credential fetch, and exported into diagnostics as such.
last_message_at
property
last_message_at: float | None
Return the monotonic time of the last inbound message, or None if none yet.
Set on every inbound message before parsing, so any message -- even one whose payload fails to decode -- proves the pipe is alive. This is the liveness clock the observability/watchdog layer consumes.
connected
property
connected: bool
Return whether the last on_connect callback reported success.
last_message_at_for
last_message_at_for(mid) -> float | None
Return when a frame naming this mid last arrived, or None.
One session carries every hub on the account, so "is push up" and "is this hub sending" are different questions. The session clock answers the first and this answers the second, which is the only one that goes quiet when a single hub stops reporting.
add_state_listener
add_state_listener(listener: Callable[[], None]) -> None
Register a callback fired whenever connection state or liveness changes.
A consumer's diagnostic views register here so that a connect/disconnect/message transition re-renders them immediately; their live state is not carried in the polled data.
remove_state_listener
remove_state_listener(listener: Callable[[], None]) -> None
Unregister a previously added state listener; tolerant of absence.
async_start
async
async_start() -> None
Launch the supervisor task that owns connect->run->reconnect.
Never blocks -- callers must schedule this as a background task; the supervisor itself retries indefinitely and this method never raises out in a way that should block config-entry setup.
on_http_relogin
on_http_relogin() -> None
Signal that the HTTP layer rotated its token: force an immediate credential re-fetch + reconnect rather than waiting for the timed renewal deadline, so the supervisor never keeps running on credentials the HTTP layer has superseded.
async_disconnect
async
async_disconnect() -> None
Cancel and await the supervisor task, then stop the paho loop and disconnect -- in that order, so no reconnect is scheduled after teardown begins. Idempotent and tolerant of a never-started/never-connected client.
decode_co2
decode_co2(raw: str) -> dict
Decode the HCS0530THO CO2, temperature and humidity payload.
STA_CO2 is declared U32, but only its low word is the reading: the high word held 1500 on every sample, as does the ASCII form's second word.
decode_flow_meter
decode_flow_meter(raw: str) -> dict
Decode HCS008FRF (flow meter).
Every datapoint the meter sends is read structurally, by the catalog field index rather than a byte offset, and the twelve records in a captured frame account for exactly the twelve dpCodes the catalog declares for model code 80 with nothing left over.
Volumes arrive as tenths of a liter and durations as whole seconds. The "current" pair reads zero whenever no run is in progress, which is the state the RainPoint app renders as "--", so those two readings sit at zero between runs rather than going unknown.
decode_hcs005frf
decode_hcs005frf(raw: str) -> dict
Decode HCS005FRF (moisture-only sensor).
decode_hcs014arf
decode_hcs014arf(raw: str) -> dict
Decode HCS014ARF (Temperature/Humidity).
decode_hcs015arf
decode_hcs015arf(raw: str) -> dict
Decode HCS015ARF (pool temperature sensor).
decode_hcs024frf_v1
decode_hcs024frf_v1(raw: str) -> dict
Decode HCS024FRF-V1 (multi-sensor).
decode_hcs044frf
decode_hcs044frf(raw: str) -> dict
Decode HCS044FRF (rain detector).
Detects rain, does not measure it: the frame carries no rainfall totals, and RainPoint's product data declares none either.
Every field is read structurally. Captured frames carry STA_BAT, STA_RSSI, STA_RAIN, STA_EVTIME, STA_ALARM and STA_REPTIME in that order.
Based on a reporter's payload: 10#DC01E1CB0010B7DC73021A20FF0F46013C1A
STA_EVTIME and STA_ALARM are deliberately not read. One reporter's event stamp predates the sensor's installation, so what it marks is unsettled, and no capture pairs a non-zero alarm with a known device state.
decode_hcs0528arf
decode_hcs0528arf(raw: str) -> dict
Decode HCS0528ARF (pool temperature sensor).
The registry's only entry for this model, and therefore the line every HCS0528ARF payload is dispatched through. It carried a no-cover pragma while MODEL_POOL held a second, shadowing entry for the same string; that entry is gone, so this line is covered through the registry like any other decoder rather than excused as an unreached stub.
decode_hic801w
decode_hic801w(raw: str) -> dict
Decode an HIC801W 8-station irrigation controller status frame (10# prefix).
Fields are located structurally with parse_entries, the same primitive the model-agnostic decoder itself calls, rather than a hand-rolled byte-offset walk: registering this model in HAND_WRITTEN_MODELS locks it out of the model-agnostic path by construction, so reaching for that decoder from inside this one would blur the boundary that set exists to draw.
STA_WATER_ZONES is read per byte, never as its declared S32: b0 is the running station number (1-based, 0 meaning none, never a bitmask - station 3 reads 03 not 04), b1 is the bitmask of stations enrolled in the running program, b2 is the bitmask of stations already completed, and b3 is 00 in all 22 captures across both units with an unknown meaning. A non-zero b3 is rejected outright: it means the per-byte reading is not the one the evidence covers, most likely a >8-station sibling or a firmware using the high half, and this is the one decision that can make a real device go dark, which is why the rejection is a WARNING rather than a silent failure.
STA_TS_DET (field 38) arrives 2 bytes wide against a declared 4 in every capture from both units, so it is never width-checked and never read: a width check there would reject every real frame, and its meaning is unpinned regardless.
Both the happy and error envelopes carry the same {"type", "rssi_dbm",
"raw_bytes", "current_station", "program_stations",
"program_stations_completed", "run_duration_seconds", "run_ends_at",
"decoder"} keys, built by _hic801w_error_envelope on the failure side:
type stays "irrigation_controller" on both branches, which is what
keeps RainPointSubDeviceEntity.available True on a failed decode, and
every decoded field is None (never 0 or []) on the error branch, since a
0 or an empty list would render as real state ("none", or an empty
program) rather than as "did not parse". No key is ever added for
STA_RAIN, STA_RH, STA_TS_DET or b3, not even as an attribute, so no
downstream surface can pick up a reading whose meaning is unverified.
decode_htv145frf
decode_htv145frf(raw: str) -> dict
Decode a single-outlet water timer status frame (10# prefix).
Covers the HTV113FRF, HTV145FRF and HTV157B: one outlet, one record of each datapoint, and no per-record dp_id, so records key on the structural field index alone. Read through parse_entries rather than a fixed-width marker table, because the HTV157B writes a 4-byte duration where the other two write 2 and a width table mis-frames it.
hub_online comes from zone presence, the same evidence decode_htv210b and the HTV213 fallback use. The 0xDC record these frames carry is the STA_BAT flag, not an online state; reading it as one hid the battery flag and gated valve availability on a charge reading.
Output shape matches the other valve decoders (type "valve_hub" with a zones dict) so valve.py and number.py consume it unchanged.
decode_htv210b
decode_htv210b(raw: str) -> dict
Decode an HTV210B valve status frame (11# prefix, hub-paired).
The HTV210B is a Bluetooth valve that becomes an ordinary RF sub-device once paired through a hub; Bluetooth-only, it reports nothing to the cloud at all, so this decoder only ever sees hub-paired frames. The frame is the same self-describing record stream the generic decoder walks, so records are located structurally: this firmware writes records in widths the HTV213 family does not (a 4-byte duration), and the walk handles both.
hub_online comes from zone presence, the same evidence the HTV213 decoder falls back on: this model's dp 0x18 record is its battery flag, not an online state, so there is no dedicated record to read.
decode_htv210b_dp_state
decode_htv210b_dp_state(raw: str) -> dict | None
Decode the comma-form state blob controlWorkModeDP returns.
The response carries a leading mode digit, a comma, then the same
self-describing record stream decode_htv210b walks -- but with no
per-record dp_id, since the response describes exactly one zone rather
than the whole hub. parse_entries is therefore called with
dp_id_prefixed=False here, not True as in the poll-path decoder.
Returns a single zone dict with exactly the four keys
_zone_from_reads produces (open, duration_seconds,
state_raw, event_time): no type, rssi_dbm,
battery_flag, zones wrapper, or port field, because the blob does
not carry those and does not say which zone it describes -- the
commanded port comes from the caller. Returns None on any malformed
input (no comma, an odd-length or empty hex body, or a body with no
work-state record) so a caller's existing falsy bail-out covers it,
rather than raising or returning a partial dict.
decode_htv213frf_valve
decode_htv213frf_valve(raw: str) -> dict
Decode HTV213FRF/HTV245FRF valve hub payload.
These devices support two formats:
1. Hex format (11#... or 01#...) - [dp_id][header][value...] records, walked
structurally
2. ASCII format (1,-84,1;...) - uses comma-separated values
decode_hws019wrf_v2
decode_hws019wrf_v2(raw: str) -> dict
Decode HWS019WRF-V2 (Display Hub) CSV/semicolon payload. Example: '1,0,1;707(707/694/1),42(42/39/1),P=9709(9709/9701/1),'
Format: current_value(day-max/day-min/unknown) - 707 = current temperature (70.7°F) - 42 = current humidity (42%) - P=9709 = current pressure (970.9 mb)
The bracketed triple is the running daily max and min, in the same units as the current value. In the sample above the max equals the current value for all three readings, which is what a reading sitting at its daily high looks like, so that sample alone cannot distinguish max/min from a repeat of the current value.
The ordering is fixed by captures where the pair straddles the current value. Those captures come from outside this repo, so they are cited here rather than left as an unexplained assertion:
brettmeyerowitz/homeassistant-homgar tests/fixtures/payloads/HWS019WRF-V2.json '1,0,1;758(798/750/1),54(54/46/1),P=8569(8569/8540/1),' 750 < 758 < 798 Remboooo/homgarapi homgarapi/devices.py '755(1020/588/1),54(91/24/1),' 588 < 755 < 1020
Across 28 hub and air-sensor samples from those sources, no value violates min <= current <= max and 7 straddle outright. This supersedes the earlier 'current/min_or_max/count' reading, which was a deliberate hedge recorded when the ordering was still unverified.
The third field is 1 in every sample seen so far and its meaning is unknown, so it is preserved verbatim rather than named.
decode_moisture_full
decode_moisture_full(raw: str) -> dict
Decode HCS021FRF (moisture + temp + lux).
Supports two formats: 1. Hex format (10#...) - standard TLV structure 2. ASCII format (1,-73,1;694,70,G=292478) - comma-separated values
decode_moisture_simple
decode_moisture_simple(raw: str) -> dict
Decode HCS026FRF (moisture-only) payload. Layout after '10#': b0 = 0xE1 b1 = RSSI (signed int8) b2 = 0x00 b3 = 0xDC b4 = 0x01 b5 = 0x88 (moisture tag) b6 = moisture % (0-100) b7.. = trailing STA_REPTIME record (0xFF 0x0F + 4-byte packed wall clock)
Based on actual payload: 10#E1C600DC01881AFF0F5E21F718 E1 C6 00 DC 01 88 1A FF 0F 5E 21 F7 18 b[1]=0xC6=198-256=-58 RSSI b[4]=0x01 STA_BAT flag b[6]=0x1A=26% moisture
The offsets above are the frame's record boundaries: this is the same self-describing encoding the 11# frames use, without the per-record dp_id. Battery and report time are read structurally rather than at these fixed offsets, so a firmware that reorders or omits a record cannot silently shift them onto another datapoint's bytes.
decode_packed_timestamp
decode_packed_timestamp(value: int) -> str | None
Decode a packed wall-clock stamp into an ISO string, or None if unusable.
The 4-byte 0xB7 records hold a little-endian word whose bit fields are, from the top: year (offset from 2020), month, day, hour, minute, second. Two independent captures confirm the layout - one frame's trailing stamp decodes to the day that capture was taken, and a mid-run frame's zone event time is exactly that frame's report time plus the zone's remaining duration.
The stamp carries no timezone and the device appears to report local wall time, so the returned string is deliberately naive: labelling it UTC would shift every reading by the viewer's offset. A zero value means "no event" and yields None, as does any word whose fields do not form a real date.
decode_pool
decode_pool(raw: str) -> dict
Decode the HCS0528ARF / HCS015ARF pool temperature payload.
The frame is walked structurally by dpCode rather than read at fixed offsets, because the leading bytes are not a datapoint record and a positional read lands on them. The catalog declares exactly STA_TEM, STA_TREND, STA_BAT and STA_REPTIME for these models.
STA_TEM is signed and carries Fahrenheit x 10 regardless of the unit the RainPoint app is set to display: a reporter running the app in Celsius confirmed a raw 622 against an app reading of 16.8 C.
STA_TREND is left undecoded. No capture pairs its value with a known direction, and nothing reads it.
decode_pool_plus
decode_pool_plus(raw: str) -> dict
Decode the HCS015ARF+ pool and ambient temperature/humidity payload.
A dp_id-framed stream: each read is keyed on (dp_id, field) and width-checked, so a record from another datapoint leaves its reading None. Temperatures are signed Fahrenheit x 10; ranges pack low then high. The frame has no RSSI record.
decode_rain
decode_rain(raw: str) -> dict
Decode HCS012ARF (rain gauge). Layout after '10#': b0 = 0xE1 b1 = 0x00 (seems constant in your samples) b2 = 0x00 b3,4 = FD,04 ; b5,b6 = lastHour raw10 LE b7,8 = FD,05 ; b9,b10 = last24h raw10 LE b11,12 = FD,06 ; b13,b14 = last7d raw10 LE b15,16 = DC,01 b17 = 0x97 ; b18,b19 = total raw10 LE b20,b21 = 0x00,0x00 b22..b27 = trailing STA_REPTIME record (0xFF 0x0F + 4-byte packed wall clock)
Battery is the STA_BAT record at b15,b16, read structurally rather than at these offsets; the 0xFF 0x0F pair is that trailing record's extended-type header, not a battery word.
Based on actual payload: 10#E10000FD040000FD054E07FD064E07DC01974E070000FF0F0410F718 E1 00 00 FD 04 00 00 FD 05 4E 07 FD 06 4E 07 DC 01 97 4E 07 00 00 FF 0F 04 10 F7 18 b[5:6]=0x0000=0.0mm last hour b[9:10]=0x074E=1870mm10 → 187.0mm last 24h b[13:14]=0x074E=1870mm10 → 187.0mm last 7d b[18:19]=0x074E=1870mm*10 → 187.0mm total
decode_temphum
decode_temphum(raw: str) -> dict
Decode the HCS014ARF temperature and humidity payload.
decode_unknown
decode_unknown(raw: str) -> dict
Decode unknown device.
decode_valve_hub
decode_valve_hub(raw: str) -> dict
Decode an irrigation valve hub TLV payload (e.g. HTV0540FRF).
Confirmed DP map (derived from live payload capture): - Zone N state DP = _VALVE_HUB_DP_HUB_STATE + N (0x19 = zone 1, 0x1A = zone 2, ...) - Zone N duration DP = _VALVE_HUB_DP_BASE_DURATION + N (0x25 = zone 1, 0x26 = zone 2, ...)
DP 0x18 itself is the STA_BAT flag, not a link state, so hub_online comes from zone presence the way every sibling valve decoder derives it. Reading that byte as an online state took every zone unavailable on a hub whose batteries had gone low.
decode_generic
decode_generic(raw: str, model: str | None = None, model_code: int | str | None = None) -> dict
Best-effort, model-agnostic decode of a payload for diagnostics.
Returns a dict shaped as::
{
"decoder": "generic-tlv",
"dp_id_prefixed": bool,
"fields": [
{"name": "STA_BAT", "index": 31, "dp_id": 24,
"raw": "01", "value": 1},
...
],
"field_names": ["STA_BAT", "STA_WKSTATE", "STA_DURATION", ...],
}
On any parse failure it returns {"decoder": "generic-tlv", "error": ...}
- it never raises, so a malformed payload surfaces as an error field rather
than an exception the caller has to catch.
A payload using the comma-and-semicolon ASCII framing ([flags],[rssi],
[flags];...) is read for its header only. The result carries both
"error" and "fields" together - unlike the hex failure paths, which
carry "error" alone - because the header rssi is a genuine reading even
though the body is declined. "fields" holds at most one entry, a
synthetic STA_RSSI field with "index", "dp_id" and "raw" all
None (there is no byte-stream position behind a header-derived
value) or is empty when the header rssi is non-negative or unparseable.
"ascii_framed" is True on this result and absent - never False -
on every hex result; see is_ascii_declined. The catalog annotation
step below never runs for an ASCII result: a header-derived field has no
structural index for it to match against.
When model is given, each field whose position matches an entry in the
committed product catalog for that model additionally carries a "catalog"
sub-dict: {"dp_port": ..., "data_type": ..., "declared_width": ...,
"signed": ..., "port_number": ..., "width_mismatch": bool}. Both
"declared_width" and "signed" are None when RainPoint does not declare
them. The catalog only annotates - a field's "value"
and "raw" are never modified by this step. A field with no catalog match,
a model with no catalog entry, or a model of None all leave the field
dict exactly as it is without model (no "catalog" key at all).
model_code disambiguates models RainPoint maps to several codes whose
port counts differ. Passing it is what lets the lookup pick the right
variant; omitting it for such a model yields no annotation rather than a
coin-flip between variants.
is_ascii_declined
is_ascii_declined(generic: dict | None) -> bool
True when a decode_generic result went through the declined-ASCII branch.
Public-named rather than underscore-prefixed to match has_declared_width, the existing guard in this codebase that crosses a module boundary for the same reason: generic_control's readback needs to refuse an ASCII-framed result explicitly rather than relying on its fields list happening to be run-state-free.
Fails closed on None, on a non-dict, and on any hex result, because the marker is never set to False - only left absent - on those. A caller cannot distinguish "this was a hex result" from "this was never decoded" from this function's return value alone, and must not try.
get_catalog_entry
get_catalog_entry(model: str | None, model_code: int | str | None = None) -> list | None
Return the catalog's trimmed dp list for a model variant, or None on a miss.
See _resolve_variant for how a (model, model_code) pair resolves to one variant, and why an ambiguous pair deliberately returns None.
get_catalog_fingerprint
get_catalog_fingerprint() -> str | None
Return the committed catalog snapshot's short content hash, or None.
get_catalog_port_number
get_catalog_port_number(model: str | None, model_code: int | str | None = None) -> int | None
Return the declared port (zone) count for a model variant, or None on a miss.
None means "the catalog does not say", which is distinct from 0 ("the RainPoint declares no ports"): several models are 0 ports under one modelCode and many under another, so a caller must not read a missing value as zero.
get_catalog_variant_codes
get_catalog_variant_codes(model: str | None) -> tuple[str, ...]
Return the modelCodes the catalog lists for a model, sorted; empty when unknown.
Lets a caller tell "this model is absent from the catalog" apart from "this model is present but the device did not say which variant it is", which are different problems with different fixes and would otherwise both surface as a plain lookup miss. The uncoded bucket is reported under its own sentinel rather than omitted, so a caller never sees an empty tuple for a model the catalog does carry.
has_bluetooth_control_identity
has_bluetooth_control_identity(model: str | None, model_code: int | str | None = None) -> bool
Return True when model's catalog variant declares BLUETOOTH_CONTROL_IDENTITY.
A resolved variant answers for itself, including a variant that declares no datapoints at all: the catalog saying nothing about control is a negative, not an absence of an answer.
An unresolved (model, model_code) pair is the one that used to be collapsed into the RF negative, and it is the failure this reads for: a catalog refresh that gives an already-supported Bluetooth valve a new model code would drop it onto the RF endpoint, which rejects that model outright, so the zone would get valve control that errors on every command. The fallback asks the model's other variants instead, and routes to the datapoint endpoint only when every one of them declares the identity. No model in the committed catalog mixes the two endpoints across its variants, so unanimity is the model's answer rather than a guess at the variant's.
A model absent from the catalog still returns False, which is what keeps
a degraded snapshot (_product_catalog loads to an empty catalog rather
than raising) from withdrawing the RF routing every install depends on.
A hand-written model states its endpoint in models.MODELS instead; this
answers for every other model, never an ad-hoc model string or list.
is_hand_written_model
is_hand_written_model(model: str | None) -> bool
Return True when model already has a hand-written, trusted decoder.
decode_packed_report_time
decode_packed_report_time(raw: int) -> str | None
Unpack a 32-bit STA_REPTIME word into an ISO-8601 local wall-clock string.
Bit layout, most significant first: 6 bits year (from
_REPORT_TIME_BASE_YEAR), 4 month, 5 day, 5 hour, 6 minute, 6 second.
The value carries no UTC offset, so the result is deliberately naive: it is
the device's own wall clock, not a point on the timeline. Out-of-range
fields (a malformed or misaligned frame) yield None rather than a
fabricated date.
encode_dp_duration_param
encode_dp_duration_param(seconds: int) -> str
Encode a duration in seconds as the param string controlWorkModeDP reads.
The endpoint carries the run duration as an unsigned 4-byte little-endian
hex string with no separator and no prefix, in place of a duration
field: 60 becomes "3C000000". Clamped rather than raised on an
out-of-range input -- a negative value clamps to 0 and anything past the
4-byte ceiling clamps to "FFFFFFFF" -- because a caller-side
OverflowError here would surface to the user as a failed valve command
with no diagnostic.
f10_to_c
f10_to_c(temp_raw_f10: int) -> float
Convert temperature from F*10 to Celsius.
is_ascii_payload
is_ascii_payload(raw: str) -> bool
True when raw is the comma-and-semicolon ASCII framing, not a hex body.
Three clauses, all required: "#" is absent (a NN# prefix always
wins and routes to the hex path first -- every payload
split_prefix's tail-truncation branch was written for carries that
prefix, so it is routed away before this test is ever reached); ";"
is present, separating the header from the body;
and a "," appears in the pre-semicolon header, matching the
[flags],[rssi],[flags];... shape both hand-written ASCII decoders in
_decoders.py already parse. Deliberately not requiring the full
three-part header here: an ASCII-shaped payload with a short or malformed
header must still route here and be declined by the ASCII branch, never
fall through to the hex path to be misreported as a hex parse failure
(the fail-closed rule this module's caller depends on). The stricter
three-part check belongs to _parse_ascii_rssi, which reads the header
once it has already been routed here. Mirrors the ordering the two
routers in _decoders.py use: hex prefix checked first, ASCII shape
checked as the fallback.
parse_entries
parse_entries(data: list[int], dp_id_prefixed: bool) -> list[dict]
Walk the self-describing byte stream into structural entries.
Header byte layout, derived from our captured payloads:
- bit 7 selects the form.
- Compact form (bit 7 clear): the whole field is this one byte; the field
index is (byte >> 4) & 7 and the byte is its own value.
- Wide form (bit 7 set): bits 0-1 give extra_len so the value spans
extra_len + 1 bytes after the header; bits 2-6 give index5.
index5 <= 30 means field index index5 + 8; index5 == 31 is
the extended escape where the real index lives in the next byte.
Returns {"dp_id", "field", "value_bytes"} dicts (value_bytes excludes
the header byte). A trailing record the frame ends inside is dropped rather
than returned short, so a caller reading it gets no value instead of a
wrong one.
parse_hub_broadcast_flag
parse_hub_broadcast_flag(param: object) -> bool | None
Read the hub record's param index-1 broadcast flag, or None when it
cannot be trusted.
param arrives from a cloud JSON document with no guaranteed type, so
anything other than a str is rejected outright -- bool is included in
that rejection deliberately, since it is an int subclass and would
otherwise pass a naive isinstance(param, str)-adjacent check by
accident on a caller that forgot the order.
The gate is a minimum-index test (len(fields) > _HUB_BROADCAST_FIELD_INDEX),
never an exact-field-count test: a hub whose param carries three or five
pipe-delimited fields still has a recoverable index 1, and an exact-count
gate would put such a hub permanently unknown even though nothing here
needs to understand its other fields. Do not tighten this to match the
four fields the one observed hub happens to produce.
Returns True for the token "1" at that index, False for "0", and None for
anything else -- a missing/empty/short param, a non-str param, or an
unrecognised token. Like _parse_ascii_rssi, this never raises and never
logs at any level: it runs on every poll for an affected hub, so a log
line here would be per-poll spam rather than a one-off diagnostic.
parse_sub_power_mode
parse_sub_power_mode(param: object) -> str | None
Read a sub-device record's param key-5 transmission-power mode, or None.
param arrives from a cloud JSON document with no guaranteed type, so
anything other than a str is rejected outright -- bool is included in
that rejection deliberately, for the same reason parse_hub_broadcast_flag
excludes it.
The blob is split on the comma delimiter into an ordered list of raw
tokens. Every token must contain exactly one =; a token with none or with
two returns None immediately. No key may repeat -- a duplicated key
anywhere in the blob, key 5 or otherwise, returns None rather than letting
a later occurrence silently win, which is the dict-coalescing key loss
this gate exists to prevent. Key 5 must be present, and its value must be a
member of _SUB_POWER_MODE_WIRE_VALUES; any other key and any other
value are read as opaque and simply carried past unvalidated.
The key count is deliberately not fixed to the four other keys (11, 12, 50, 51) the one observed device happens to produce: a blob carrying a key nobody has yet identified, alongside a valid key 5, still parses. Do not tighten this to an exact key set.
Returns the canonical one-character mode digit ("0", "1", or "2") on
success, None on any failure. Like parse_hub_broadcast_flag, this never
raises and never logs at any level: it runs on every poll for an affected
sub-device, so a log line here would be per-poll spam rather than a
one-off diagnostic.
splice_hub_broadcast_param
splice_hub_broadcast_param(param: object, enabled: bool) -> str | None
Return param with only index 1 replaced by enabled, or
None when the same gate that blocks the read blocks the write.
Calls parse_hub_broadcast_flag itself as the gate -- not a
re-implementation of it -- so the two functions cannot drift apart on
what counts as readable: a param this module could not itself parse to
a bool (wrong type, too few fields, or an index-1 token that is neither
"0" nor "1") never reaches the split-and-replace below. On success the
string is split on the delimiter, the element at
_HUB_BROADCAST_FIELD_INDEX is replaced with the literal "1" or "0", and
the result is rejoined on the same delimiter. Every other element is
carried across untouched and unparsed: no strip, no case change, no
re-encode, no normalisation, no defaulting of an empty field. The output
field count always equals the input field count, and adjacent delimiters
-- which denote empty fields -- survive as the same empty fields. The
replacement token is always one of these two local literals; it is never
derived from the input, so no cloud-supplied text can reach the field
this function writes. Never raises, never logs at any level, for the same
reason parse_hub_broadcast_flag does not.
splice_sub_power_mode
splice_sub_power_mode(param: object, mode: str) -> str | None
Return param with only key 5's value token replaced, or None when the
same gate that blocks the read blocks the write.
Calls parse_sub_power_mode itself as the gate -- not a re-implementation
of it -- so the two functions cannot drift apart on what counts as
readable: a param this module could not itself parse (wrong type, a
malformed token, a duplicate key, an absent key 5, or an unrecognised
key-5 value) never reaches the splice below. mode must itself be one of
the three canonical digits; anything else returns None.
On success, the blob is split on the delimiter and rejoined; only the
token whose parsed key is the key-5 key has its value replaced, and the
replacement keeps the character width of the value it replaced (a
two-character value in yields a two-character value out, matching the
only write shape the cloud has been observed to accept). Every other
token -- keys 11, 12, 50, 51 and anything not yet identified -- is carried
across byte for byte, unparsed, unstripped, un-normalised, in its original
position. This never rebuilds the string from parsed keys and never
routes it through a dict, so a duplicate key cannot silently coalesce.
Never raises, never logs at any level, for the same reason
parse_sub_power_mode does not.
split_prefix
split_prefix(raw: str) -> tuple[str, bool]
Return (hex_body, dp_id_prefixed) from a NN#... payload.
dp_id_prefixed is true for the 11# framing, where each entry starts
with a one-byte dp_id. The 10# framing has no per-entry dp_id.
summarize_record
summarize_record(record: object) -> str
Render a cloud record as its shape and key names, never its values.
This is the shape every log line on a cloud-record path uses instead of dumping the record itself. Summarising rather than redacting field by field is deliberate: a redaction list has to be maintained against a payload nobody here controls, and it fails silently the first time the vendor adds a field. A key-and-count summary has the opposite failure mode, because a new field shows up as a name with no value attached.
Nested values are counted, not walked. A list reports its length and the union of its items' keys, so a status response reads as "n=4" plus the field set rather than four device records in full.
Output is bounded on both axes. The reported n is always the true length, but at most _SUMMARY_MAX_ITEMS items are walked to collect keys and at most _SUMMARY_MAX_KEYS names are rendered, because nothing here controls how large a cloud response can be.
valid_rssi_dbm
valid_rssi_dbm(value) -> int | None
Return a signal reading only when it is one, else None.
A dBm reading off these radios is negative. Zero or a positive number means the frame carried no signal record and something upstream supplied a placeholder or read the wrong byte, and publishing it puts a number in front of the user where unknown is the honest answer. Applied where the reading is written rather than where it is read, so the attributes and the diagnostics dump inherit the same guarantee the reading does.
Note the shape this cannot catch: a negative number read out of the wrong byte is still negative. Only a structural read fixes that, which is why the dp_id-prefixed decoders locate their record rather than trusting an offset.
battery_flag_is_low
battery_flag_is_low(flag: int | None) -> bool | None
Map a raw STA_BAT flag to low/normal, or None when unproven.
battery_flag_to_percent
battery_flag_to_percent(flag: int | None) -> int | None
Map a raw STA_BAT flag to a percentage, or None when unproven.
No capture pairs a flag with a charge level, so no flag earns a measured percentage: a wrong number would be indistinguishable from a real one. Only the proven-healthy flag reads as full, which is the same value battery_flag_is_low answers not-low on: the two read one byte and may not disagree about it.
aiorainpoint.models
Model identifiers and the table of models with a hand-written decoder.
MODELS maps each hand-written model to its decoder, its device family and,
for controllable models, the run-duration unit and write endpoint. Every field
is stated per row rather than derived from the product catalog, so a catalog
that fails to load cannot change how a supported device decodes or is driven.
HCS005FRF
module-attribute
HCS005FRF = 'HCS005FRF'
HCS008FRF
module-attribute
HCS008FRF = 'HCS008FRF'
HCS012ARF
module-attribute
HCS012ARF = 'HCS012ARF'
HCS014ARF
module-attribute
HCS014ARF = 'HCS014ARF'
HCS015ARF
module-attribute
HCS015ARF = 'HCS015ARF'
HCS015ARF_PLUS
module-attribute
HCS015ARF_PLUS = 'HCS015ARF+'
HCS021FRF
module-attribute
HCS021FRF = 'HCS021FRF'
HCS024FRF_V1
module-attribute
HCS024FRF_V1 = 'HCS024FRF-V1'
HCS026FRF
module-attribute
HCS026FRF = 'HCS026FRF'
HCS044FRF
module-attribute
HCS044FRF = 'HCS044FRF'
HCS0528ARF
module-attribute
HCS0528ARF = 'HCS0528ARF'
HCS0530THO
module-attribute
HCS0530THO = 'HCS0530THO'
HTV113FRF
module-attribute
HTV113FRF = 'HTV113FRF'
HTV145FRF
module-attribute
HTV145FRF = 'HTV145FRF'
HTV157B
module-attribute
HTV157B = 'HTV157B'
HTP160FRF
module-attribute
HTP160FRF = 'HTP160FRF'
HTP115FRF
module-attribute
HTP115FRF = 'HTP115FRF'
HTV213FRF
module-attribute
HTV213FRF = 'HTV213FRF'
HTV245FRF
module-attribute
HTV245FRF = 'HTV245FRF'
HTV345FRF
module-attribute
HTV345FRF = 'HTV345FRF'
HTV405FRF
module-attribute
HTV405FRF = 'HTV405FRF'
HTV445FRF
module-attribute
HTV445FRF = 'HTV445FRF'
HTV0540FRF
module-attribute
HTV0540FRF = 'HTV0540FRF'
HTV210B
module-attribute
HTV210B = 'HTV210B'
HIC801W
module-attribute
HIC801W = 'HIC801W'
HWS019WRF_V2
module-attribute
HWS019WRF_V2 = 'HWS019WRF-V2'
VALVE_FAMILIES
module-attribute
VALVE_FAMILIES = frozenset({Family.SINGLE_OUTLET_TIMER, Family.ZONE_VALVE, Family.VALVE_HUB, Family.BT_VALVE})
MODELS
module-attribute
MODELS: Mapping[str, ModelSpec] = MappingProxyType({HCS005FRF: _sensor(_d.decode_hcs005frf), HCS008FRF: _sensor(_d.decode_flowmeter), HCS012ARF: _sensor(_d.decode_rain), HCS014ARF: _sensor(_d.decode_temphum), HCS015ARF: _sensor(_d.decode_hcs015arf), HCS015ARF_PLUS: _sensor(_d.decode_pool_plus), HCS021FRF: _sensor(_d.decode_moisture_full), HCS024FRF_V1: _sensor(_d.decode_hcs024frf_v1), HCS026FRF: _sensor(_d.decode_moisture_simple), HCS044FRF: _sensor(_d.decode_hcs044frf), HCS0528ARF: _sensor(_d.decode_hcs0528arf), HCS0530THO: _sensor(_d.decode_co2), HTV113FRF: _valve(_d.decode_htv145frf, Family.SINGLE_OUTLET_TIMER), HTV145FRF: _valve(_d.decode_htv145frf, Family.SINGLE_OUTLET_TIMER), HTV157B: _valve(_d.decode_htv145frf, Family.SINGLE_OUTLET_TIMER), HTP160FRF: _valve(_d.decode_htv145frf, Family.SINGLE_OUTLET_TIMER), HTP115FRF: _valve(_d.decode_htv145frf, Family.SINGLE_OUTLET_TIMER), HTV213FRF: _valve(_d.decode_htv213frf_valve, Family.ZONE_VALVE), HTV245FRF: _valve(_d.decode_htv213frf_valve, Family.ZONE_VALVE), HTV345FRF: _valve(_d.decode_htv213frf_valve, Family.ZONE_VALVE), HTV405FRF: _valve(_d.decode_htv213frf_valve, Family.ZONE_VALVE), HTV445FRF: _valve(_d.decode_htv213frf_valve, Family.ZONE_VALVE), HTV0540FRF: _valve(_d.decode_valve_hub, Family.VALVE_HUB), HTV210B: _valve(_d.decode_htv210b, Family.BT_VALVE, ControlEndpoint.WORK_MODE_DP), HIC801W: ModelSpec(_d.decode_hic801w, Family.STATION_CONTROLLER, DurationUnit.MINUTES, ControlEndpoint.WORK_MODE), HWS019WRF_V2: ModelSpec(_d.decode_hws019wrf_v2, Family.DISPLAY_HUB)})
HAND_WRITTEN_MODELS
module-attribute
HAND_WRITTEN_MODELS: frozenset[str] = frozenset(MODELS)
Family
Bases: StrEnum
Entity shape a model gets; the decoder is chosen per row, not per family.
SINGLE_OUTLET_TIMER
class-attribute
instance-attribute
SINGLE_OUTLET_TIMER = 'single_outlet_timer'
ZONE_VALVE
class-attribute
instance-attribute
ZONE_VALVE = 'zone_valve'
VALVE_HUB
class-attribute
instance-attribute
VALVE_HUB = 'valve_hub'
BT_VALVE
class-attribute
instance-attribute
BT_VALVE = 'bt_valve'
STATION_CONTROLLER
class-attribute
instance-attribute
STATION_CONTROLLER = 'station_controller'
DISPLAY_HUB
class-attribute
instance-attribute
DISPLAY_HUB = 'display_hub'
SENSOR
class-attribute
instance-attribute
SENSOR = 'sensor'
DurationUnit
Bases: StrEnum
Unit the device's run-duration command field reads.
SECONDS
class-attribute
instance-attribute
SECONDS = 'seconds'
MINUTES
class-attribute
instance-attribute
MINUTES = 'minutes'
ControlEndpoint
Bases: StrEnum
Cloud endpoint a model's valve commands go through.
WORK_MODE
class-attribute
instance-attribute
WORK_MODE = 'controlWorkMode'
WORK_MODE_DP
class-attribute
instance-attribute
WORK_MODE_DP = 'controlWorkModeDP'
ModelSpec
dataclass
ModelSpec(decoder: Callable[[str], dict], family: Family, duration_unit: DurationUnit | None = None, control_endpoint: ControlEndpoint | None = None)
One hand-written model: its decoder, family and, if controllable, its control fields.
decoder
instance-attribute
decoder: Callable[[str], dict]
family
instance-attribute
family: Family
duration_unit
class-attribute
instance-attribute
duration_unit: DurationUnit | None = None
control_endpoint
class-attribute
instance-attribute
control_endpoint: ControlEndpoint | None = None