From 42376bda5bcdfb0a84f7dcafe660905375090dd2 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Thu, 24 Apr 2025 23:12:03 +0200 Subject: [PATCH] Change the location_accuracy type for the DeviceTracker entity class to float (#2653) --- blog/2025-04-24-device-tracker-accuracy.md | 27 ++++++++++++++++++++++ docs/core/entity/device-tracker.md | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 blog/2025-04-24-device-tracker-accuracy.md diff --git a/blog/2025-04-24-device-tracker-accuracy.md b/blog/2025-04-24-device-tracker-accuracy.md new file mode 100644 index 00000000..33af72b8 --- /dev/null +++ b/blog/2025-04-24-device-tracker-accuracy.md @@ -0,0 +1,27 @@ +--- +author: Jan Bouwhuis +authorURL: https://github.com/jbouwh +authorImageURL: https://avatars.githubusercontent.com/u/7188918?s=96&v=4 +title: Device tracker TrackerEntity location accuracy attribute type change +--- + +The type of `location_accuracy` attribute (short hand `_attr_location_accuracy`) of the `TrackerEntity` class of the `device_tracker` entity component has been changed from `int` to `float`. + +Type conversions in case the source value is a `float` are no longer needed. + +### Example + +```python +class ExampleTrackerEntity(TrackerEntity): + """Test tracker entity.""" + + _attr_location_accuracy: float = 2.5 + + @cached_property + def location_accuracy(self) -> float: + """Return the location accuracy of the device. + + Value in meters. + """ + return self._attr_location_accuracy +``` diff --git a/docs/core/entity/device-tracker.md b/docs/core/entity/device-tracker.md index dd1eeadd..cc0c259d 100644 --- a/docs/core/entity/device-tracker.md +++ b/docs/core/entity/device-tracker.md @@ -48,7 +48,7 @@ Properties should always only return information from memory and not do I/O (lik | ----------------- | ------------------------------ | ---------------- | ---------------------------------------- | | battery_level | int | None | `None` | The battery level of the device. | | latitude | float | None | `None` | The latitude coordinate of the device. | -| location_accuracy | `int` | `0` | The location accuracy (m) of the device. | +| location_accuracy | `float` | `0` | The location accuracy (m) of the device. | | location_name | str | None | `None` | The location name of the device. | | longitude | float | None | `None` | The longitude coordinate of the device. | | source_type | SourceType | `SourceType.GPS` | The source type of the device. |