mirror of
https://github.com/home-assistant/core.git
synced 2026-09-17 05:58:41 +01:00
Add SwitchBot Universal Remote Control battery sensor (#174101)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Fan Kai <fankai@onero.com> Co-authored-by: Ludovic BOUÉ <lboue@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
Fan Kai
Ludovic BOUÉ
parent
152ca3f515
commit
401bcae006
@@ -203,6 +203,7 @@ PLATFORMS_BY_TYPE = {
|
||||
Platform.SENSOR,
|
||||
],
|
||||
SupportedModels.WEATHER_STATION.value: [Platform.SENSOR],
|
||||
SupportedModels.UNIVERSAL_REMOTE.value: [Platform.SENSOR],
|
||||
SupportedModels.CANDLE_WARMER_LAMP.value: [Platform.LIGHT, Platform.SENSOR],
|
||||
SupportedModels.RGBIC_NEON_ROPE_LIGHT.value: [Platform.LIGHT, Platform.SENSOR],
|
||||
SupportedModels.RGBIC_NEON_WIRE_ROPE_LIGHT.value: [
|
||||
@@ -226,6 +227,7 @@ CLASS_BY_DEVICE = {
|
||||
SupportedModels.ROLLER_SHADE.value: switchbot.SwitchbotRollerShade,
|
||||
SupportedModels.CIRCULATOR_FAN.value: switchbot.SwitchbotFan,
|
||||
SupportedModels.STANDING_FAN.value: switchbot.SwitchbotStandingFan,
|
||||
SupportedModels.UNIVERSAL_REMOTE.value: switchbot.SwitchbotUniversalRemote,
|
||||
SupportedModels.S10_VACUUM.value: switchbot.SwitchbotVacuum,
|
||||
SupportedModels.S20_VACUUM.value: switchbot.SwitchbotVacuum,
|
||||
SupportedModels.K10_VACUUM.value: switchbot.SwitchbotVacuum,
|
||||
|
||||
@@ -73,6 +73,7 @@ class SupportedModels(StrEnum):
|
||||
LOCK_PRO_WIFI = "lock_pro_wifi"
|
||||
WEATHER_STATION = "weather_station"
|
||||
STANDING_FAN = "standing_fan"
|
||||
UNIVERSAL_REMOTE = "universal_remote"
|
||||
CANDLE_WARMER_LAMP = "candle_warmer_lamp"
|
||||
RGBIC_NEON_ROPE_LIGHT = "rgbic_neon_rope_light"
|
||||
RGBIC_NEON_WIRE_ROPE_LIGHT = "rgbic_neon_wire_rope_light"
|
||||
@@ -127,6 +128,7 @@ CONNECTABLE_SUPPORTED_MODEL_TYPES = {
|
||||
SwitchbotModel.LOCK_VISION: SupportedModels.LOCK_VISION,
|
||||
SwitchbotModel.LOCK_PRO_WIFI: SupportedModels.LOCK_PRO_WIFI,
|
||||
SwitchbotModel.STANDING_FAN: SupportedModels.STANDING_FAN,
|
||||
SwitchbotModel.UNIVERSAL_REMOTE: SupportedModels.UNIVERSAL_REMOTE,
|
||||
SwitchbotModel.CANDLE_WARMER_LAMP: SupportedModels.CANDLE_WARMER_LAMP,
|
||||
SwitchbotModel.RGBIC_NEON_ROPE_LIGHT: SupportedModels.RGBIC_NEON_ROPE_LIGHT,
|
||||
SwitchbotModel.RGBIC_NEON_WIRE_ROPE_LIGHT: (
|
||||
|
||||
@@ -589,6 +589,31 @@ CIRCULATOR_FAN_SERVICE_INFO = BluetoothServiceInfoBleak(
|
||||
)
|
||||
|
||||
|
||||
UNIVERSAL_REMOTE_SERVICE_INFO = BluetoothServiceInfoBleak(
|
||||
name="Universal Remote",
|
||||
manufacturer_data={
|
||||
2409: b"\xaa\xbb\xcc\xdd\xee\xff\x00\x50\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
},
|
||||
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"'\x00"},
|
||||
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
|
||||
address="AA:BB:CC:DD:EE:FF",
|
||||
rssi=-60,
|
||||
source="local",
|
||||
advertisement=generate_advertisement_data(
|
||||
local_name="Universal Remote",
|
||||
manufacturer_data={
|
||||
2409: b"\xaa\xbb\xcc\xdd\xee\xff\x00\x50\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
},
|
||||
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"'\x00"},
|
||||
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
|
||||
),
|
||||
device=generate_ble_device("AA:BB:CC:DD:EE:FF", "Universal Remote"),
|
||||
time=0,
|
||||
connectable=True,
|
||||
tx_power=-127,
|
||||
)
|
||||
|
||||
|
||||
K20_VACUUM_SERVICE_INFO = BluetoothServiceInfoBleak(
|
||||
name="K20 Vacuum",
|
||||
manufacturer_data={
|
||||
|
||||
@@ -41,6 +41,7 @@ from . import (
|
||||
PRESENCE_SENSOR_SERVICE_INFO,
|
||||
RELAY_SWITCH_2PM_SERVICE_INFO,
|
||||
REMOTE_SERVICE_INFO,
|
||||
UNIVERSAL_REMOTE_SERVICE_INFO,
|
||||
WEATHER_STATION_SERVICE_INFO,
|
||||
WOHAND_SERVICE_INFO,
|
||||
WOHUB2_SERVICE_INFO,
|
||||
@@ -293,6 +294,45 @@ async def test_remote(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_universal_remote_sensor(hass: HomeAssistant) -> None:
|
||||
"""Test setting up the Universal Remote battery sensor."""
|
||||
await async_setup_component(hass, DOMAIN, {})
|
||||
inject_bluetooth_service_info(hass, UNIVERSAL_REMOTE_SERVICE_INFO)
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
CONF_NAME: "test-name",
|
||||
CONF_SENSOR_TYPE: "universal_remote",
|
||||
},
|
||||
unique_id="aabbccddeeff",
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all("sensor")) == 2
|
||||
|
||||
battery_sensor = hass.states.get("sensor.test_name_battery")
|
||||
battery_sensor_attrs = battery_sensor.attributes
|
||||
assert battery_sensor.state == "80"
|
||||
assert battery_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Battery"
|
||||
assert battery_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "%"
|
||||
assert battery_sensor_attrs[ATTR_STATE_CLASS] == "measurement"
|
||||
|
||||
rssi_sensor = hass.states.get("sensor.test_name_bluetooth_signal")
|
||||
rssi_sensor_attrs = rssi_sensor.attributes
|
||||
assert rssi_sensor.state == "-60"
|
||||
assert rssi_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Bluetooth signal"
|
||||
assert rssi_sensor_attrs[ATTR_UNIT_OF_MEASUREMENT] == "dBm"
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_hub2_sensor(hass: HomeAssistant) -> None:
|
||||
"""Test setting up creates the sensor for WoHub2."""
|
||||
|
||||
Reference in New Issue
Block a user