diff --git a/tests/components/switchbot/__init__.py b/tests/components/switchbot/__init__.py index 3235a9e8cd3..f30f72892ba 100644 --- a/tests/components/switchbot/__init__.py +++ b/tests/components/switchbot/__init__.py @@ -59,7 +59,7 @@ WOHAND_SERVICE_INFO = BluetoothServiceInfoBleak( manufacturer_data={89: b"\xfd`0U\x92W"}, service_data={"00000d00-0000-1000-8000-00805f9b34fb": b"H\x90\xd9"}, service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"], - address="aa:bb:cc:dd:ee:ff", + address="AA:BB:CC:DD:EE:FF", rssi=-60, source="local", advertisement=AdvertisementData( @@ -68,7 +68,7 @@ WOHAND_SERVICE_INFO = BluetoothServiceInfoBleak( service_data={"00000d00-0000-1000-8000-00805f9b34fb": b"H\x90\xd9"}, service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"], ), - device=BLEDevice("aa:bb:cc:dd:ee:ff", "WoHand"), + device=BLEDevice("AA:BB:CC:DD:EE:FF", "WoHand"), time=0, connectable=True, ) diff --git a/tests/components/switchbot/test_config_flow.py b/tests/components/switchbot/test_config_flow.py index 71b7018a6b3..66d0874809f 100644 --- a/tests/components/switchbot/test_config_flow.py +++ b/tests/components/switchbot/test_config_flow.py @@ -45,7 +45,7 @@ async def test_bluetooth_discovery(hass): assert result["type"] == FlowResultType.CREATE_ENTRY assert result["title"] == "Bot EEFF" assert result["data"] == { - CONF_ADDRESS: "aa:bb:cc:dd:ee:ff", + CONF_ADDRESS: "AA:BB:CC:DD:EE:FF", CONF_SENSOR_TYPE: "bot", } @@ -148,7 +148,7 @@ async def test_user_setup_wohand(hass): assert result["type"] == FlowResultType.CREATE_ENTRY assert result["title"] == "Bot EEFF" assert result["data"] == { - CONF_ADDRESS: "aa:bb:cc:dd:ee:ff", + CONF_ADDRESS: "AA:BB:CC:DD:EE:FF", CONF_SENSOR_TYPE: "bot", } diff --git a/tests/components/switchbot/test_sensor.py b/tests/components/switchbot/test_sensor.py new file mode 100644 index 00000000000..ae77c5a8de4 --- /dev/null +++ b/tests/components/switchbot/test_sensor.py @@ -0,0 +1,58 @@ +"""Test the switchbot sensors.""" + + +from homeassistant.components.sensor import ATTR_STATE_CLASS +from homeassistant.components.switchbot.const import DOMAIN +from homeassistant.const import ( + ATTR_FRIENDLY_NAME, + ATTR_UNIT_OF_MEASUREMENT, + CONF_ADDRESS, + CONF_NAME, + CONF_PASSWORD, + CONF_SENSOR_TYPE, +) +from homeassistant.setup import async_setup_component + +from . import WOHAND_SERVICE_INFO + +from tests.common import MockConfigEntry +from tests.components.bluetooth import inject_bluetooth_service_info + + +async def test_sensors(hass, entity_registry_enabled_by_default): + """Test setting up creates the sensors.""" + await async_setup_component(hass, DOMAIN, {}) + inject_bluetooth_service_info(hass, WOHAND_SERVICE_INFO) + + entry = MockConfigEntry( + domain=DOMAIN, + data={ + CONF_ADDRESS: "aa:bb:cc:dd:ee:ff", + CONF_NAME: "test-name", + CONF_PASSWORD: "test-password", + CONF_SENSOR_TYPE: "bot", + }, + 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 == "89" + 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_rssi") + rssi_sensor_attrs = rssi_sensor.attributes + assert rssi_sensor.state == "-60" + assert rssi_sensor_attrs[ATTR_FRIENDLY_NAME] == "test-name Rssi" + 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()