mirror of
https://github.com/home-assistant/core.git
synced 2026-04-17 15:44:52 +01:00
Fix MQTT device tracker overrides via JSON state attributes without reset (#165529)
This commit is contained in:
committed by
Franck Nijhof
parent
46555c6d9a
commit
743eeeae53
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user