mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Change here_travel_time update interval to 30min (#147222)
This commit is contained in:
committed by
GitHub
parent
32688e1108
commit
da3a164e66
@@ -6,9 +6,14 @@ import logging
|
||||
|
||||
from homeassistant.const import CONF_API_KEY, CONF_MODE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.issue_registry import (
|
||||
IssueSeverity,
|
||||
async_create_issue,
|
||||
async_delete_issue,
|
||||
)
|
||||
from homeassistant.helpers.start import async_at_started
|
||||
|
||||
from .const import CONF_TRAFFIC_MODE, TRAVEL_MODE_PUBLIC
|
||||
from .const import CONF_TRAFFIC_MODE, DOMAIN, TRAVEL_MODE_PUBLIC
|
||||
from .coordinator import (
|
||||
HereConfigEntry,
|
||||
HERERoutingDataUpdateCoordinator,
|
||||
@@ -24,6 +29,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: HereConfigEntry)
|
||||
"""Set up HERE Travel Time from a config entry."""
|
||||
api_key = config_entry.data[CONF_API_KEY]
|
||||
|
||||
alert_for_multiple_entries(hass)
|
||||
|
||||
cls: type[HERETransitDataUpdateCoordinator | HERERoutingDataUpdateCoordinator]
|
||||
if config_entry.data[CONF_MODE] in {TRAVEL_MODE_PUBLIC, "publicTransportTimeTable"}:
|
||||
cls = HERETransitDataUpdateCoordinator
|
||||
@@ -42,6 +49,29 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: HereConfigEntry)
|
||||
return True
|
||||
|
||||
|
||||
def alert_for_multiple_entries(hass: HomeAssistant) -> None:
|
||||
"""Check if there are multiple entries for the same API key."""
|
||||
if len(hass.config_entries.async_entries(DOMAIN)) > 1:
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"multiple_here_travel_time_entries",
|
||||
learn_more_url="https://www.home-assistant.io/integrations/here_travel_time/",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="multiple_here_travel_time_entries",
|
||||
translation_placeholders={
|
||||
"pricing_page": "https://www.here.com/get-started/pricing",
|
||||
},
|
||||
)
|
||||
else:
|
||||
async_delete_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"multiple_here_travel_time_entries",
|
||||
)
|
||||
|
||||
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, config_entry: HereConfigEntry
|
||||
) -> bool:
|
||||
|
||||
@@ -44,7 +44,7 @@ from .coordinator import (
|
||||
HERETransitDataUpdateCoordinator,
|
||||
)
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=5)
|
||||
SCAN_INTERVAL = timedelta(minutes=30)
|
||||
|
||||
|
||||
def sensor_descriptions(travel_mode: str) -> tuple[SensorEntityDescription, ...]:
|
||||
|
||||
@@ -107,5 +107,11 @@
|
||||
"name": "Destination"
|
||||
}
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"multiple_here_travel_time_entries": {
|
||||
"title": "More than one HERE Travel Time integration detected",
|
||||
"description": "HERE deprecated the previous free tier. You have change to the Base Plan which has 5000 instead of 30000 free requests per month.\n\nSince you have more than one HERE Travel Time integration configured, you will need to disable or remove the additional integrations to avoid exceeding the free request limit.\nYou can ignore this issue if you are okay with the additional cost."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ from homeassistant.components.here_travel_time.const import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
from .const import DEFAULT_CONFIG
|
||||
|
||||
@@ -80,3 +81,29 @@ async def test_migrate_entry_v1_1_v1_2(
|
||||
assert updated_entry.state is ConfigEntryState.LOADED
|
||||
assert updated_entry.minor_version == 2
|
||||
assert updated_entry.options[CONF_TRAFFIC_MODE] is True
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("valid_response")
|
||||
async def test_issue_multiple_here_integrations_detected(
|
||||
hass: HomeAssistant, issue_registry: ir.IssueRegistry
|
||||
) -> None:
|
||||
"""Test that an issue is created when multiple HERE integrations are detected."""
|
||||
entry1 = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="1234567890",
|
||||
data=DEFAULT_CONFIG,
|
||||
options=DEFAULT_OPTIONS,
|
||||
)
|
||||
entry2 = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="0987654321",
|
||||
data=DEFAULT_CONFIG,
|
||||
options=DEFAULT_OPTIONS,
|
||||
)
|
||||
entry1.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(entry1.entry_id)
|
||||
entry2.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(entry2.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(issue_registry.issues) == 1
|
||||
|
||||
Reference in New Issue
Block a user