Skip to content

Commit 9efbcb2

Browse files
authored
Add model information for probe_plus devices (home-assistant#154262)
1 parent f210bb3 commit 9efbcb2

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

homeassistant/components/probe_plus/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from homeassistant.const import Platform
5+
from homeassistant.const import CONF_MODEL, Platform
66
from homeassistant.core import HomeAssistant
77

88
from .coordinator import ProbePlusConfigEntry, ProbePlusDataUpdateCoordinator
@@ -12,6 +12,12 @@
1212

1313
async def async_setup_entry(hass: HomeAssistant, entry: ProbePlusConfigEntry) -> bool:
1414
"""Set up Probe Plus from a config entry."""
15+
# Perform a migration to ensure the model is added to the config entry schema.
16+
if CONF_MODEL not in entry.data:
17+
# The config entry adds the model number of the device to the start of its title
18+
hass.config_entries.async_update_entry(
19+
entry, data={**entry.data, CONF_MODEL: entry.title.split(" ")[0]}
20+
)
1521
coordinator = ProbePlusDataUpdateCoordinator(hass, entry)
1622
await coordinator.async_config_entry_first_refresh()
1723
entry.runtime_data = coordinator

homeassistant/components/probe_plus/config_flow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
async_discovered_service_info,
1414
)
1515
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
16-
from homeassistant.const import CONF_ADDRESS
16+
from homeassistant.const import CONF_ADDRESS, CONF_MODEL
1717

1818
from .const import DOMAIN
1919

@@ -73,6 +73,7 @@ async def async_step_bluetooth_confirm(
7373
title=discovery.title,
7474
data={
7575
CONF_ADDRESS: discovery.discovery_info.address,
76+
CONF_MODEL: discovery.discovery_info.name,
7677
},
7778
)
7879
self._set_confirm_only()
@@ -95,7 +96,7 @@ async def async_step_user(
9596
discovery = self._discovered_devices[address]
9697
return self.async_create_entry(
9798
title=discovery.title,
98-
data=user_input,
99+
data={**user_input, CONF_MODEL: discovery.discovery_info.name},
99100
)
100101

101102
current_addresses = self._async_current_ids()

homeassistant/components/probe_plus/entity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pyprobeplus import ProbePlusDevice
66

7+
from homeassistant.const import CONF_MODEL
78
from homeassistant.helpers.device_registry import (
89
CONNECTION_BLUETOOTH,
910
DeviceInfo,
@@ -40,6 +41,7 @@ def __init__(
4041
name=coordinator.device.name,
4142
manufacturer="Probe Plus",
4243
suggested_area="Kitchen",
44+
model=coordinator.config_entry.data.get(CONF_MODEL),
4345
connections={(CONNECTION_BLUETOOTH, coordinator.device.mac)},
4446
)
4547

tests/components/probe_plus/test_config_flow.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from homeassistant.components.probe_plus.const import DOMAIN
99
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_USER
10-
from homeassistant.const import CONF_ADDRESS
10+
from homeassistant.const import CONF_ADDRESS, CONF_MODEL
1111
from homeassistant.core import HomeAssistant
1212
from homeassistant.data_entry_flow import FlowResultType
1313
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
@@ -57,7 +57,7 @@ async def test_user_config_flow_creates_entry(
5757
assert result["type"] is FlowResultType.CREATE_ENTRY
5858
assert result["result"].unique_id == "aa:bb:cc:dd:ee:ff"
5959
assert result["title"] == "FM210 aa:bb:cc:dd:ee:ff"
60-
assert result["data"] == {CONF_ADDRESS: "aa:bb:cc:dd:ee:ff"}
60+
assert result["data"] == {CONF_ADDRESS: "aa:bb:cc:dd:ee:ff", CONF_MODEL: "FM210"}
6161

6262

6363
async def test_user_flow_already_configured(
@@ -97,9 +97,7 @@ async def test_bluetooth_discovery(
9797
assert result["type"] is FlowResultType.CREATE_ENTRY
9898
assert result["title"] == "FM210 aa:bb:cc:dd:ee:ff"
9999
assert result["result"].unique_id == "aa:bb:cc:dd:ee:ff"
100-
assert result["data"] == {
101-
CONF_ADDRESS: service_info.address,
102-
}
100+
assert result["data"] == {CONF_ADDRESS: service_info.address, CONF_MODEL: "FM210"}
103101

104102

105103
async def test_already_configured_bluetooth_discovery(

0 commit comments

Comments
 (0)