custom-components / places

Component to integrate with OpenStreetMap Reverse Geocode (places)
GNU General Public License v3.0
110 stars 22 forks source link

Attributes are not updated properly when used as a country sensor #283

Closed NODeeJay closed 3 months ago

NODeeJay commented 3 months ago

My bug is quite a specific edge case.

I use places just to show the country I am in in the sensor value, which works perfectly. Recently, I started to process also an attribute of that sensor, place_type. However, even though my location changes several types, the attribute(s) seem to stick. When I add the place_type to the Display Options, it updates the attributes quite fast.

To reproduce:

  1. Create country sensor with the display options place[country_code]
  2. Use fake GPS or other mock location tools to set your location
  3. HA changes the location correctly from home to away
  4. Places sensor sticks to the old location, which is correctly CZ, but also the attributes do not change

I assume the issue is because I do not request the attribute to be updated, the Display Options just contain the country code.

The log also show it reverts the values, although the response from OSM processed my home address and not Profi Auto CZ.

2024-06-01 23:30:20.949 DEBUG (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) Keeping initial last_place_name
2024-06-01 23:30:20.949 INFO (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) last_place_name: Profi Auto CZ
2024-06-01 23:30:20.949 DEBUG (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) Initial Advanced Display Options: place[country_code]
2024-06-01 23:30:20.949 DEBUG (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) [get_option_state] State: None
2024-06-01 23:30:20.949 DEBUG (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) [get_option_state] State: CZ
2024-06-01 23:30:20.949 DEBUG (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) [get_option_state] State after incl/excl: CZ
2024-06-01 23:30:20.950 DEBUG (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) [adv_options] Updated state list: ['CZ']
2024-06-01 23:30:20.950 DEBUG (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) New State from Advanced Display Options: CZ
2024-06-01 23:30:20.950 INFO (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) No entity update needed, Previous State = New State
2024-06-01 23:30:20.951 DEBUG (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) Reverting attributes back to before the update started
2024-06-01 23:30:20.951 INFO (SyncWorker_42) [custom_components.places.sensor] (Country Sensor Alex) End of Update

To confirm my theory, I removed place_type again from the Display Options and moved the position around, but as before it did not update the attributes anymore.

Unfortunately, the full log is some work to sanitize before publishing it online, but I can send it to you by PM/mail. I can live with the workaround, if I process an attribute later or cut of 3 digits and process it from the sensor value is not a big deal in my case.

NODeeJay commented 3 months ago

I realized it works when Use GPS Accuracy is off.