def make_advertisement(address: str, payload: bytes) -> BluetoothServiceInfoBleak: """Make a dummy advertisement.""" return BluetoothServiceInfoBleak( name="Test Device", address=address, device=BLEDevice(address, None), rssi=-56, manufacturer_data={}, service_data={ "0000181c-0000-1000-8000-00805f9b34fb": payload, }, service_uuids=["0000181c-0000-1000-8000-00805f9b34fb"], source="local", advertisement=AdvertisementData(local_name="Test Device"), time=0, connectable=False, )
"""Tests for the Yale Access Bluetooth integration.""" from bleak.backends.device import BLEDevice from bleak.backends.scanner import AdvertisementData from homeassistant.components.bluetooth import BluetoothServiceInfoBleak YALE_ACCESS_LOCK_DISCOVERY_INFO = BluetoothServiceInfoBleak( name="M1012LU", address="AA:BB:CC:DD:EE:FF", rssi=-60, manufacturer_data={ 465: b"\x00\x00\xd1\xf0b;\xd8\x1dE\xd6\xba\xeeL\xdd]\xf5\xb2\xe9", 76: b"\x061\x00Z\x8f\x93\xb2\xec\x85\x06\x00i\x00\x02\x02Q\xed\x1d\xf0", }, service_uuids=[], service_data={}, source="local", device=BLEDevice(address="AA:BB:CC:DD:EE:FF", name="M1012LU"), advertisement=AdvertisementData(), time=0, connectable=True, ) LOCK_DISCOVERY_INFO_UUID_ADDRESS = BluetoothServiceInfoBleak( name="M1012LU", address="61DE521B-F0BF-9F44-64D4-75BBE1738105", rssi=-60, manufacturer_data={ 465: b"\x00\x00\xd1\xf0b;\xd8\x1dE\xd6\xba\xeeL\xdd]\xf5\xb2\xe9", 76:
if not skip_entry_setup: await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() return entry WOHAND_SERVICE_INFO = BluetoothServiceInfoBleak( name="WoHand", 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", rssi=-60, source="local", advertisement=AdvertisementData( local_name="WoHand", 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"], ), device=BLEDevice("aa:bb:cc:dd:ee:ff", "WoHand"), time=0, connectable=True, ) WOHAND_SERVICE_INFO_NOT_CONNECTABLE = BluetoothServiceInfoBleak( name="WoHand", 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",
async def test_preserve_new_tracked_device_name(hass, mock_bluetooth, mock_device_tracker_conf): """Test preserving tracked device name across new seens.""" address = "DE:AD:BE:EF:13:37" name = "Mock device name" entity_id = f"{DOMAIN}.{slugify(name)}" with patch( "homeassistant.components.bluetooth.async_discovered_service_info" ) as mock_async_discovered_service_info, patch.object( device_tracker, "MIN_SEEN_NEW", 3): device = BluetoothServiceInfoBleak( name=name, address=address, rssi=-19, manufacturer_data={}, service_data={}, service_uuids=[], source="local", device=BLEDevice(address, None), advertisement=AdvertisementData(local_name="empty"), time=0, connectable=False, ) # Return with name when seen first time mock_async_discovered_service_info.return_value = [device] config = { CONF_PLATFORM: "bluetooth_le_tracker", CONF_SCAN_INTERVAL: timedelta(minutes=1), CONF_TRACK_NEW: True, } result = await async_setup_component(hass, DOMAIN, {DOMAIN: config}) assert result # Seen once here; return without name when seen subsequent times device = BluetoothServiceInfoBleak( name=None, address=address, rssi=-19, manufacturer_data={}, service_data={}, service_uuids=[], source="local", device=BLEDevice(address, None), advertisement=AdvertisementData(local_name="empty"), time=0, connectable=False, ) # Return with name when seen first time mock_async_discovered_service_info.return_value = [device] # Tick until device seen enough times for to be registered for tracking for _ in range(device_tracker.MIN_SEEN_NEW - 1): async_fire_time_changed( hass, dt_util.utcnow() + config[CONF_SCAN_INTERVAL] + timedelta(seconds=1), ) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state assert state.name == name
async def test_tracking_battery_successful(hass, mock_bluetooth, mock_device_tracker_conf): """Test tracking the battery gets a value.""" address = "DE:AD:BE:EF:13:37" name = "Mock device name" entity_id = f"{DOMAIN}.{slugify(name)}" with patch( "homeassistant.components.bluetooth.async_discovered_service_info" ) as mock_async_discovered_service_info, patch.object( device_tracker, "MIN_SEEN_NEW", 3): device = BluetoothServiceInfoBleak( name=name, address=address, rssi=-19, manufacturer_data={}, service_data={}, service_uuids=[], source="local", device=BLEDevice(address, None), advertisement=AdvertisementData(local_name="empty"), time=0, connectable=True, ) # Return with name when seen first time mock_async_discovered_service_info.return_value = [device] config = { CONF_PLATFORM: "bluetooth_le_tracker", CONF_SCAN_INTERVAL: timedelta(minutes=1), CONF_TRACK_BATTERY: True, CONF_TRACK_BATTERY_INTERVAL: timedelta(minutes=2), CONF_TRACK_NEW: True, } result = await async_setup_component(hass, DOMAIN, {DOMAIN: config}) assert result # Tick until device seen enough times for to be registered for tracking for _ in range(device_tracker.MIN_SEEN_NEW - 1): async_fire_time_changed( hass, dt_util.utcnow() + config[CONF_SCAN_INTERVAL] + timedelta(seconds=1), ) await hass.async_block_till_done() with patch( "homeassistant.components.bluetooth_le_tracker.device_tracker.BleakClient", MockBleakClientBattery5, ): # Wait for the battery scan async_fire_time_changed( hass, dt_util.utcnow() + config[CONF_SCAN_INTERVAL] + timedelta(seconds=1) + timedelta(minutes=2), ) await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.name == name assert state.attributes["battery"] == 5
"""Tests for the SensorPush integration.""" from bleak.backends.device import BLEDevice from bleak.backends.scanner import AdvertisementData from homeassistant.components.bluetooth import BluetoothServiceInfoBleak NOT_SENSOR_PUSH_SERVICE_INFO = BluetoothServiceInfoBleak( name="Not it", address="00:00:00:00:00:00", device=BLEDevice("00:00:00:00:00:00", None), rssi=-63, manufacturer_data={3234: b"\x00\x01"}, service_data={}, service_uuids=[], source="local", advertisement=AdvertisementData(local_name="Not it"), time=0, connectable=False, ) LYWSDCGQ_SERVICE_INFO = BluetoothServiceInfoBleak( name="LYWSDCGQ", address="58:2D:34:35:93:21", device=BLEDevice("00:00:00:00:00:00", None), rssi=-63, manufacturer_data={}, service_data={ "0000fe95-0000-1000-8000-00805f9b34fb": b"P \xaa\x01\xda!\x9354-X\r\x10\x04\xfe\x00H\x02" },
"""Tests for the BThome integration.""" from bleak.backends.device import BLEDevice from bleak.backends.scanner import AdvertisementData from homeassistant.components.bluetooth import BluetoothServiceInfoBleak TEMP_HUMI_SERVICE_INFO = BluetoothServiceInfoBleak( name="ATC 8D18B2", address="A4:C1:38:8D:18:B2", device=BLEDevice("A4:C1:38:8D:18:B2", None), rssi=-63, manufacturer_data={}, service_data={ "0000181c-0000-1000-8000-00805f9b34fb": b"#\x02\xca\t\x03\x03\xbf\x13" }, service_uuids=["0000181c-0000-1000-8000-00805f9b34fb"], source="local", advertisement=AdvertisementData(local_name="Not it"), time=0, connectable=False, ) TEMP_HUMI_ENCRYPTED_SERVICE_INFO = BluetoothServiceInfoBleak( name="TEST DEVICE 8F80A5", address="54:48:E6:8F:80:A5", device=BLEDevice("54:48:E6:8F:80:A5", None), rssi=-63, manufacturer_data={}, service_data={ "0000181e-0000-1000-8000-00805f9b34fb":
"""Tests for the LED BLE Bluetooth integration.""" from bleak.backends.device import BLEDevice from bleak.backends.scanner import AdvertisementData from homeassistant.components.bluetooth import BluetoothServiceInfoBleak LED_BLE_DISCOVERY_INFO = BluetoothServiceInfoBleak( name="Triones:F30200000152C", address="AA:BB:CC:DD:EE:FF", rssi=-60, manufacturer_data={}, service_uuids=[], service_data={}, source="local", device=BLEDevice(address="AA:BB:CC:DD:EE:FF", name="Triones:F30200000152C"), advertisement=AdvertisementData(), time=0, connectable=True, ) UNSUPPORTED_LED_BLE_DISCOVERY_INFO = BluetoothServiceInfoBleak( name="LEDnetWFF30200000152C", address="AA:BB:CC:DD:EE:FF", rssi=-60, manufacturer_data={}, service_uuids=[], service_data={}, source="local", device=BLEDevice(address="AA:BB:CC:DD:EE:FF", name="LEDnetWFF30200000152C"), advertisement=AdvertisementData(), time=0,
"""Tests for the Fjäråskupan integration.""" from bleak.backends.device import BLEDevice from bleak.backends.scanner import AdvertisementData from homeassistant.components.bluetooth import BluetoothServiceInfoBleak COOKER_SERVICE_INFO = BluetoothServiceInfoBleak( name="COOKERHOOD_FJAR", address="AA:BB:CC:DD:EE:FF", rssi=-60, manufacturer_data={}, service_uuids=[], service_data={}, source="local", device=BLEDevice(address="AA:BB:CC:DD:EE:FF", name="COOKERHOOD_FJAR"), advertisement=AdvertisementData(), time=0, connectable=True, )