mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
prusalink: expose printer location as suggested_area (#170099)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
bb6087cf87
commit
191143d12d
@@ -25,4 +25,5 @@ class PrusaLinkEntity(CoordinatorEntity[PrusaLinkUpdateCoordinator]):
|
||||
serial_number=info_data.get("serial"),
|
||||
sw_version=version_data.get("firmware"),
|
||||
configuration_url=self.coordinator.api.client.host,
|
||||
suggested_area=info_data.get("location"),
|
||||
)
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
"filename": {
|
||||
"default": "mdi:file-image-outline"
|
||||
},
|
||||
"location": {
|
||||
"default": "mdi:map-marker"
|
||||
},
|
||||
"material": {
|
||||
"default": "mdi:palette-swatch-variant"
|
||||
},
|
||||
|
||||
@@ -215,13 +215,6 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = {
|
||||
value_fn=lambda data: cast(str, data["nozzle_diameter"]),
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||
key="info.location",
|
||||
translation_key="location",
|
||||
value_fn=lambda data: cast(str, data["location"]),
|
||||
supported_fn=lambda data: data.get("location") is not None,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||
key="info.min_extrusion_temp",
|
||||
translation_key="min_extrusion_temp",
|
||||
|
||||
@@ -54,9 +54,6 @@
|
||||
"heatbed_temperature": {
|
||||
"name": "Heatbed temperature"
|
||||
},
|
||||
"location": {
|
||||
"name": "Location"
|
||||
},
|
||||
"material": {
|
||||
"name": "Material"
|
||||
},
|
||||
|
||||
@@ -12,7 +12,11 @@ from homeassistant.components.prusalink.config_flow import ConfigFlow
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
||||
from homeassistant.helpers import (
|
||||
area_registry as ar,
|
||||
device_registry as dr,
|
||||
issue_registry as ir,
|
||||
)
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
@@ -24,8 +28,9 @@ async def test_device_info(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
area_registry: ar.AreaRegistry,
|
||||
) -> None:
|
||||
"""Test device info is populated with serial number and firmware version."""
|
||||
"""Test device info is populated with serial number, firmware, and suggested area."""
|
||||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
|
||||
device = device_registry.async_get_device(
|
||||
@@ -35,6 +40,13 @@ async def test_device_info(
|
||||
assert device.serial_number == "serial-1337"
|
||||
assert device.sw_version == "6.1.2+11023"
|
||||
|
||||
# `location` from /api/v1/info is set as suggested_area; the device gets
|
||||
# placed in that area (created on the fly when not pre-existing).
|
||||
assert device.area_id is not None
|
||||
area = area_registry.async_get_area(device.area_id)
|
||||
assert area is not None
|
||||
assert area.name == "Workshop"
|
||||
|
||||
|
||||
async def test_unloading(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -335,16 +335,12 @@ async def test_axis_x_y_not_created_when_absent(
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_location_and_min_extrusion_temp_sensors(
|
||||
async def test_min_extrusion_temp_sensor(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_api: None
|
||||
) -> None:
|
||||
"""Test location and minimum extrusion temperature sensors from info endpoint."""
|
||||
"""Test minimum extrusion temperature sensor from info endpoint."""
|
||||
assert await async_setup_component(hass, "prusalink", {})
|
||||
|
||||
state = hass.states.get("sensor.mock_title_location")
|
||||
assert state is not None
|
||||
assert state.state == "Workshop"
|
||||
|
||||
state = hass.states.get("sensor.mock_title_minimum_extrusion_temperature")
|
||||
assert state is not None
|
||||
assert state.state == "170"
|
||||
@@ -354,16 +350,14 @@ async def test_location_and_min_extrusion_temp_sensors(
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_location_and_min_extrusion_temp_not_created_when_absent(
|
||||
async def test_min_extrusion_temp_not_created_when_absent(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_api: None,
|
||||
mock_info_api: dict[str, Any],
|
||||
) -> None:
|
||||
"""Location and min extrusion temp sensors are not created when info fields are absent."""
|
||||
del mock_info_api["location"]
|
||||
"""Min extrusion temp sensor is not created when the info field is absent."""
|
||||
del mock_info_api["min_extrusion_temp"]
|
||||
assert await async_setup_component(hass, "prusalink", {})
|
||||
|
||||
assert hass.states.get("sensor.mock_title_location") is None
|
||||
assert hass.states.get("sensor.mock_title_minimum_extrusion_temperature") is None
|
||||
|
||||
Reference in New Issue
Block a user