diff --git a/homeassistant/components/switchbot/__init__.py b/homeassistant/components/switchbot/__init__.py index 3223f24fa0273b..0226236693c2bd 100644 --- a/homeassistant/components/switchbot/__init__.py +++ b/homeassistant/components/switchbot/__init__.py @@ -198,6 +198,7 @@ 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: [ @@ -221,6 +222,7 @@ 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, diff --git a/homeassistant/components/switchbot/const.py b/homeassistant/components/switchbot/const.py index ac84e09e71f671..2a3b05d39ff727 100644 --- a/homeassistant/components/switchbot/const.py +++ b/homeassistant/components/switchbot/const.py @@ -72,6 +72,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" @@ -125,6 +126,7 @@ class SupportedModels(StrEnum): 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: ( diff --git a/tests/components/switchbot/__init__.py b/tests/components/switchbot/__init__.py index 2d2ea404620a5e..8f1159911c6ebd 100644 --- a/tests/components/switchbot/__init__.py +++ b/tests/components/switchbot/__init__.py @@ -589,6 +589,31 @@ def make_advertisement( ) +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={ diff --git a/tests/components/switchbot/test_sensor.py b/tests/components/switchbot/test_sensor.py index f242724cdb4871..03b8e22262ad68 100644 --- a/tests/components/switchbot/test_sensor.py +++ b/tests/components/switchbot/test_sensor.py @@ -41,6 +41,7 @@ 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."""