mirror of
https://github.com/home-assistant/core.git
synced 2026-10-05 16:07:36 +01:00
Add model information for probe_plus devices (#154262)
This commit is contained in:
1 parent
f210bb35ed
commit
9efbcb2f82
4 files changed
+15
-8
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.const import CONF_MODEL, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import ProbePlusConfigEntry, ProbePlusDataUpdateCoordinator
|
||||
@@ -12,6 +12,12 @@ PLATFORMS: list[Platform] = [Platform.SENSOR]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ProbePlusConfigEntry) -> bool:
|
||||
"""Set up Probe Plus from a config entry."""
|
||||
# Perform a migration to ensure the model is added to the config entry schema.
|
||||
if CONF_MODEL not in entry.data:
|
||||
# The config entry adds the model number of the device to the start of its title
|
||||
hass.config_entries.async_update_entry(
|
||||
entry, data={**entry.data, CONF_MODEL: entry.title.split(" ")[0]}
|
||||
)
|
||||
coordinator = ProbePlusDataUpdateCoordinator(hass, entry)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
entry.runtime_data = coordinator
|
||||
|
||||
@@ -13,7 +13,7 @@ from homeassistant.components.bluetooth import (
|
||||
async_discovered_service_info,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_ADDRESS
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_MODEL
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
@@ -73,6 +73,7 @@ class ProbeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
title=discovery.title,
|
||||
data={
|
||||
CONF_ADDRESS: discovery.discovery_info.address,
|
||||
CONF_MODEL: discovery.discovery_info.name,
|
||||
},
|
||||
)
|
||||
self._set_confirm_only()
|
||||
@@ -95,7 +96,7 @@ class ProbeConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
discovery = self._discovered_devices[address]
|
||||
return self.async_create_entry(
|
||||
title=discovery.title,
|
||||
data=user_input,
|
||||
data={**user_input, CONF_MODEL: discovery.discovery_info.name},
|
||||
)
|
||||
|
||||
current_addresses = self._async_current_ids()
|
||||
|
||||
@@ -4,6 +4,7 @@ from dataclasses import dataclass
|
||||
|
||||
from pyprobeplus import ProbePlusDevice
|
||||
|
||||
from homeassistant.const import CONF_MODEL
|
||||
from homeassistant.helpers.device_registry import (
|
||||
CONNECTION_BLUETOOTH,
|
||||
DeviceInfo,
|
||||
@@ -40,6 +41,7 @@ class ProbePlusEntity(CoordinatorEntity[ProbePlusDataUpdateCoordinator]):
|
||||
name=coordinator.device.name,
|
||||
manufacturer="Probe Plus",
|
||||
suggested_area="Kitchen",
|
||||
model=coordinator.config_entry.data.get(CONF_MODEL),
|
||||
connections={(CONNECTION_BLUETOOTH, coordinator.device.mac)},
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
|
||||
from homeassistant.components.probe_plus.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_ADDRESS
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_MODEL
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||
@@ -57,7 +57,7 @@ async def test_user_config_flow_creates_entry(
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].unique_id == "aa:bb:cc:dd:ee:ff"
|
||||
assert result["title"] == "FM210 aa:bb:cc:dd:ee:ff"
|
||||
assert result["data"] == {CONF_ADDRESS: "aa:bb:cc:dd:ee:ff"}
|
||||
assert result["data"] == {CONF_ADDRESS: "aa:bb:cc:dd:ee:ff", CONF_MODEL: "FM210"}
|
||||
|
||||
|
||||
async def test_user_flow_already_configured(
|
||||
@@ -97,9 +97,7 @@ async def test_bluetooth_discovery(
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "FM210 aa:bb:cc:dd:ee:ff"
|
||||
assert result["result"].unique_id == "aa:bb:cc:dd:ee:ff"
|
||||
assert result["data"] == {
|
||||
CONF_ADDRESS: service_info.address,
|
||||
}
|
||||
assert result["data"] == {CONF_ADDRESS: service_info.address, CONF_MODEL: "FM210"}
|
||||
|
||||
|
||||
async def test_already_configured_bluetooth_discovery(
|
||||
|
||||
Reference in new issue
Block a user