Compare commits

...

2 Commits

Author SHA1 Message Date
jbouwh
33af94fd14 Remove duplicatie statement 2026-03-14 11:19:19 +00:00
jbouwh
b662948113 Fix MQTT device tracker overrides via JSON state attributes without reset 2026-03-14 11:10:38 +00:00
2 changed files with 25 additions and 2 deletions

View File

@@ -163,8 +163,6 @@ class MqttDeviceTracker(MqttEntity, TrackerEntity):
latitude: float | None
longitude: float | None
gps_accuracy: float
# Reset manually set location to allow automatic zone detection
self._attr_location_name = None
if isinstance(
latitude := extra_state_attributes.get(ATTR_LATITUDE), (int, float)
) and isinstance(

View File

@@ -644,6 +644,31 @@ async def test_setting_device_tracker_location_via_abbr_reset_message(
assert state.attributes["source_type"] == "gps"
assert state.state == STATE_HOME
# Override the GPS state via a direct state update
async_fire_mqtt_message(hass, "test-topic", "office")
state = hass.states.get("device_tracker.test")
assert state.state == "office"
# Test a GPS attributes update without a reset
async_fire_mqtt_message(
hass,
"attributes-topic",
'{"latitude":32.87336,"longitude": -117.22743, "gps_accuracy":1.5}',
)
state = hass.states.get("device_tracker.test")
assert state.state == "office"
# Reset the manual set location
# This should calculate the location from GPS attributes
async_fire_mqtt_message(hass, "test-topic", "reset")
state = hass.states.get("device_tracker.test")
assert state.attributes["latitude"] == 32.87336
assert state.attributes["longitude"] == -117.22743
assert state.attributes["gps_accuracy"] == 1.5
assert state.attributes["source_type"] == "gps"
assert state.state == STATE_HOME
async def test_setting_blocked_attribute_via_mqtt_json_message(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator