- M1: supported_features += TURN_ON/TURN_OFF (сервисы в HA 2026.9), async_turn_off; удалён мёртвый _enable_turn_on_off_backwards_compat; тест turn_on/turn_off → operation_mode 1/0 - M2: достижимый диапазон = override ∩ raw-таблица шаблона; raw клампится в from_display, clamp() по достижимому диапазону (молчаливый кламп ядра устранён); тесты scaled override - M3: mock_ac сбрасывает crypto/active на DELETE; тест reload → снова ONLINE - гонка: async_sync_now больше не перезаписывает данные устаревшим снимком (ONLINE мог потеряться при быстром старте) — стабильность 4×37 тестов - m1: превью-текст учитывает выбранный в форме шаблон; m2: убрана недостижимая проверка шага; m3: удалён мёртвый translation_key climate - m4: бит 21 op_status (шаблон B); m5: lru_cache template_info/prop_info; m6: operation_mode=1 без истории → hvac_mode unknown; m7: ошибка команды → HomeAssistantError; m8: unload возвращает False, не разбирая runtime - n2: уточнены описания data_description в переводах
77 lines
2.7 KiB
Python
77 lines
2.7 KiB
Python
"""Интроспекция шаблонов/конверсий через cffi (сверка с C-таблицами)."""
|
|
from __future__ import annotations
|
|
|
|
from pyfglair import (
|
|
Prop,
|
|
Template,
|
|
ValueKind,
|
|
api_range,
|
|
convert_from_input,
|
|
convert_to_display,
|
|
detect,
|
|
prop_info,
|
|
template_info,
|
|
)
|
|
from pyfglair._cffi import ffi, lib
|
|
|
|
|
|
def test_version():
|
|
assert ffi.string(lib.fgl_version()) == b"0.1.0"
|
|
|
|
|
|
def test_detect():
|
|
assert detect("AP-WC1E") == Template.A
|
|
assert detect("AP-WB2E") == Template.B
|
|
assert detect("AP-WF3E") == Template.F
|
|
assert detect("UNKNOWN-MODEL") is None
|
|
assert detect(None) is None
|
|
assert detect("") is None
|
|
|
|
|
|
def test_template_a_properties():
|
|
info = {p.prop: p for p in template_info(Template.A)}
|
|
assert info[Prop.OPERATION_MODE].name == "operation_mode"
|
|
assert info[Prop.OPERATION_MODE].kind == ValueKind.INT
|
|
assert info[Prop.OPERATION_MODE].read_only is False
|
|
assert info[Prop.OPERATION_MODE].raw_min == 0
|
|
assert info[Prop.OPERATION_MODE].raw_max == 6
|
|
assert info[Prop.DISPLAY_TEMPERATURE].read_only is True
|
|
assert info[Prop.DISPLAY_TEMPERATURE].base_type == "integer"
|
|
assert info[Prop.DEVICE_NAME].kind == ValueKind.STRING
|
|
assert info[Prop.ADJUST_TEMPERATURE].raw_min == -100
|
|
assert info[Prop.ADJUST_TEMPERATURE].raw_max == 450
|
|
assert Prop.AF_VERTICAL_MOVE_STEP1 not in info
|
|
|
|
|
|
def test_template_b_and_f():
|
|
info_b = {p.prop: p for p in template_info(Template.B)}
|
|
assert Prop.AF_VERTICAL_MOVE_STEP1 in info_b
|
|
assert Prop.DISPLAY_TEMPERATURE not in info_b
|
|
info_f = {p.prop: p for p in template_info(Template.F)}
|
|
assert Prop.DISPLAY_TEMPERATURE in info_f
|
|
assert Prop.MONITOR1 in info_f
|
|
assert Prop.FILTER_SIGN_RESET in info_f
|
|
assert Prop.FILTER_SIGN_RESET_DISPLAY not in info_f
|
|
|
|
|
|
def test_conversions():
|
|
assert convert_to_display(Template.A, Prop.DISPLAY_TEMPERATURE, 7000) == 200
|
|
assert convert_to_display(Template.A, Prop.DISPLAY_TEMPERATURE, 5000) == 0
|
|
assert convert_to_display(Template.A, Prop.ADJUST_TEMPERATURE, 250) == 250
|
|
assert convert_from_input(Template.A, Prop.DISPLAY_TEMPERATURE, 200) == 7000
|
|
assert convert_from_input(Template.A, Prop.ADJUST_TEMPERATURE, 220) == 220
|
|
|
|
|
|
def test_template_info_is_cached():
|
|
assert template_info(Template.A) is template_info(Template.A)
|
|
assert prop_info(Template.A, Prop.FAN_SPEED) is prop_info(
|
|
Template.A, Prop.FAN_SPEED
|
|
)
|
|
|
|
|
|
def test_api_range():
|
|
assert api_range(Template.A, Prop.DISPLAY_TEMPERATURE) == (-100, 450)
|
|
assert api_range(Template.A, Prop.OPERATION_MODE) == (0, 6)
|
|
assert api_range(Template.A, Prop.DEVICE_NAME) is None
|
|
assert api_range(Template.B, Prop.DISPLAY_TEMPERATURE) is None
|