Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The GPSD integration."""
2 
3 from __future__ import annotations
4 
5 from gps3.agps3threaded import AGPS3mechanism
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_HOST, CONF_PORT, Platform
9 from homeassistant.core import HomeAssistant
10 
11 PLATFORMS: list[Platform] = [Platform.SENSOR]
12 
13 type GPSDConfigEntry = ConfigEntry[AGPS3mechanism]
14 
15 
16 async def async_setup_entry(hass: HomeAssistant, entry: GPSDConfigEntry) -> bool:
17  """Set up GPSD from a config entry."""
18  agps_thread = AGPS3mechanism()
19  entry.runtime_data = agps_thread
20 
21  def setup_agps() -> None:
22  host = entry.data.get(CONF_HOST)
23  port = entry.data.get(CONF_PORT)
24  agps_thread.stream_data(host, port)
25  agps_thread.run_thread()
26 
27  await hass.async_add_executor_job(setup_agps)
28 
29  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
30 
31  return True
32 
33 
34 async def async_unload_entry(hass: HomeAssistant, entry: GPSDConfigEntry) -> bool:
35  """Unload a config entry."""
36  if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
37  agps_thread = entry.runtime_data
38  await hass.async_add_executor_job(
39  lambda: agps_thread.stream_data(
40  host=entry.data.get(CONF_HOST),
41  port=entry.data.get(CONF_PORT),
42  enable=False,
43  )
44  )
45 
46  return unload_ok
bool async_unload_entry(HomeAssistant hass, GPSDConfigEntry entry)
Definition: __init__.py:34
bool async_setup_entry(HomeAssistant hass, GPSDConfigEntry entry)
Definition: __init__.py:16