Skip to content

Commit

Permalink
fix bug no effect with option update_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
dscao authored May 20, 2023
1 parent 1a3e71b commit 9ea85ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion custom_components/autoamap/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def async_step_user(self, user_input=None):
{
vol.Optional(
CONF_UPDATE_INTERVAL,
default=self.config_entry.options.get(CONF_UPDATE_INTERVAL, 90),
default=self.config_entry.options.get(CONF_UPDATE_INTERVAL, 60),
): vol.All(vol.Coerce(int), vol.Range(min=10, max=3600)),
vol.Optional(
CONF_GPS_CONVER,
Expand Down
4 changes: 3 additions & 1 deletion custom_components/autoamap/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
PARALLEL_UPDATES = 1
_LOGGER = logging.getLogger(__name__)

SCAN_INTERVAL = datetime.timedelta(seconds=60)

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add autoamap entities from a config_entry."""
Expand Down Expand Up @@ -156,7 +157,8 @@ async def async_update(self):
"""Update autoamap entity."""
#_LOGGER.debug("device tracker_update: %s", self.coordinator.data["MESSAGE"]["HD_STATE_TIME"])
_LOGGER.debug(datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo)
await self.coordinator.async_request_refresh()
_LOGGER.debug("刷新device_tracker数据")
#await self.coordinator.async_request_refresh()
if self._gps_conver == True:
self._coords = gcj02towgs84(self.coordinator.data["thislon"], self.coordinator.data["thislat"])
else:
Expand Down
12 changes: 7 additions & 5 deletions custom_components/autoamap/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

SENSOR_TYPES_KEYS = { description.key for description in SENSOR_TYPES }
#_LOGGER.debug("SENSOR_TYPES_KEYS: %s" ,SENSOR_TYPES_KEYS)

SCAN_INTERVAL = datetime.timedelta(seconds=60)

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add gooddriver entities from a config_entry."""
Expand Down Expand Up @@ -149,7 +149,7 @@ def state_attributes(self):
data = self.coordinator.data
if data:
attrs["querytime"] = data["querytime"]
return attrs
return attrs


async def async_added_to_hass(self):
Expand All @@ -160,8 +160,8 @@ async def async_added_to_hass(self):

async def async_update(self):
"""Update gooddriver entity."""
await self.coordinator.async_request_refresh()

_LOGGER.debug("刷新sensor数据")
#await self.coordinator.async_request_refresh()
if self.entity_description.key == KEY_PARKING_TIME:
self._state = self.coordinator.data.get(ATTR_PARKING_TIME)
elif self.entity_description.key == KEY_LASTSTOPTIME:
Expand All @@ -172,4 +172,6 @@ async def async_update(self):
else:
self._state = "unknown"

self._attrs = {ATTR_QUERYTIME: self.coordinator.data["querytime"]}
self._attrs = {ATTR_QUERYTIME: self.coordinator.data["querytime"]}


0 comments on commit 9ea85ce

Please sign in to comment.