mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Improve airthings ble (#97905)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
a234ab51fe
commit
b34ce3c792
@ -34,8 +34,12 @@ class Discovery:
|
||||
|
||||
|
||||
def get_name(device: AirthingsDevice) -> str:
|
||||
"""Generate name with identifier for device."""
|
||||
return f"{device.name} ({device.identifier})"
|
||||
"""Generate name with model and identifier for device."""
|
||||
|
||||
name = device.friendly_name()
|
||||
if identifier := device.identifier:
|
||||
name += f" ({identifier})"
|
||||
return name
|
||||
|
||||
|
||||
class AirthingsDeviceUpdateError(Exception):
|
||||
@ -156,7 +160,7 @@ class AirthingsConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_abort(reason="no_devices_found")
|
||||
|
||||
titles = {
|
||||
address: get_name(discovery.device)
|
||||
address: discovery.device.name
|
||||
for (address, discovery) in self._discovered_devices.items()
|
||||
}
|
||||
return self.async_show_form(
|
||||
|
@ -24,5 +24,5 @@
|
||||
"dependencies": ["bluetooth_adapters"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/airthings_ble",
|
||||
"iot_class": "local_polling",
|
||||
"requirements": ["airthings-ble==0.5.3"]
|
||||
"requirements": ["airthings-ble==0.5.6-2"]
|
||||
}
|
||||
|
@ -162,10 +162,11 @@ class AirthingsSensor(
|
||||
super().__init__(coordinator)
|
||||
self.entity_description = entity_description
|
||||
|
||||
name = f"{airthings_device.name} {airthings_device.identifier}"
|
||||
name = airthings_device.name
|
||||
if identifier := airthings_device.identifier:
|
||||
name += f" ({identifier})"
|
||||
|
||||
self._attr_unique_id = f"{name}_{entity_description.key}"
|
||||
|
||||
self._id = airthings_device.address
|
||||
self._attr_device_info = DeviceInfo(
|
||||
connections={
|
||||
@ -175,9 +176,10 @@ class AirthingsSensor(
|
||||
)
|
||||
},
|
||||
name=name,
|
||||
manufacturer="Airthings",
|
||||
manufacturer=airthings_device.manufacturer,
|
||||
hw_version=airthings_device.hw_version,
|
||||
sw_version=airthings_device.sw_version,
|
||||
model=airthings_device.model,
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -378,7 +378,7 @@ aioymaps==1.2.2
|
||||
airly==1.1.0
|
||||
|
||||
# homeassistant.components.airthings_ble
|
||||
airthings-ble==0.5.3
|
||||
airthings-ble==0.5.6-2
|
||||
|
||||
# homeassistant.components.airthings
|
||||
airthings-cloud==0.1.0
|
||||
|
@ -353,7 +353,7 @@ aioymaps==1.2.2
|
||||
airly==1.1.0
|
||||
|
||||
# homeassistant.components.airthings_ble
|
||||
airthings-ble==0.5.3
|
||||
airthings-ble==0.5.6-2
|
||||
|
||||
# homeassistant.components.airthings
|
||||
airthings-cloud==0.1.0
|
||||
|
@ -77,8 +77,11 @@ UNKNOWN_SERVICE_INFO = BluetoothServiceInfoBleak(
|
||||
)
|
||||
|
||||
WAVE_DEVICE_INFO = AirthingsDevice(
|
||||
manufacturer="Airthings AS",
|
||||
hw_version="REV A",
|
||||
sw_version="G-BLE-1.5.3-master+0",
|
||||
model="Wave Plus",
|
||||
model_raw="2930",
|
||||
name="Airthings Wave+",
|
||||
identifier="123456",
|
||||
sensors={
|
||||
|
@ -25,7 +25,13 @@ from tests.common import MockConfigEntry
|
||||
async def test_bluetooth_discovery(hass: HomeAssistant) -> None:
|
||||
"""Test discovery via bluetooth with a valid device."""
|
||||
with patch_async_ble_device_from_address(WAVE_SERVICE_INFO), patch_airthings_ble(
|
||||
AirthingsDevice(name="Airthings Wave+", identifier="123456")
|
||||
AirthingsDevice(
|
||||
manufacturer="Airthings AS",
|
||||
model="Wave Plus",
|
||||
model_raw="2930",
|
||||
name="Airthings Wave Plus",
|
||||
identifier="123456",
|
||||
)
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
@ -35,7 +41,9 @@ async def test_bluetooth_discovery(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "bluetooth_confirm"
|
||||
assert result["description_placeholders"] == {"name": "Airthings Wave+ (123456)"}
|
||||
assert result["description_placeholders"] == {
|
||||
"name": "Airthings Wave Plus (123456)"
|
||||
}
|
||||
|
||||
with patch_async_setup_entry():
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
@ -43,7 +51,7 @@ async def test_bluetooth_discovery(hass: HomeAssistant) -> None:
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Airthings Wave+ (123456)"
|
||||
assert result["title"] == "Airthings Wave Plus (123456)"
|
||||
assert result["result"].unique_id == "cc:cc:cc:cc:cc:cc"
|
||||
|
||||
|
||||
@ -100,7 +108,13 @@ async def test_user_setup(hass: HomeAssistant) -> None:
|
||||
"homeassistant.components.airthings_ble.config_flow.async_discovered_service_info",
|
||||
return_value=[WAVE_SERVICE_INFO],
|
||||
), patch_async_ble_device_from_address(WAVE_SERVICE_INFO), patch_airthings_ble(
|
||||
AirthingsDevice(name="Airthings Wave+", identifier="123456")
|
||||
AirthingsDevice(
|
||||
manufacturer="Airthings AS",
|
||||
model="Wave Plus",
|
||||
model_raw="2930",
|
||||
name="Airthings Wave Plus",
|
||||
identifier="123456",
|
||||
)
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
@ -112,7 +126,7 @@ async def test_user_setup(hass: HomeAssistant) -> None:
|
||||
schema = result["data_schema"].schema
|
||||
|
||||
assert schema.get(CONF_ADDRESS).container == {
|
||||
"cc:cc:cc:cc:cc:cc": "Airthings Wave+ (123456)"
|
||||
"cc:cc:cc:cc:cc:cc": "Airthings Wave Plus"
|
||||
}
|
||||
|
||||
with patch(
|
||||
@ -125,7 +139,7 @@ async def test_user_setup(hass: HomeAssistant) -> None:
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Airthings Wave+ (123456)"
|
||||
assert result["title"] == "Airthings Wave Plus (123456)"
|
||||
assert result["result"].unique_id == "cc:cc:cc:cc:cc:cc"
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user