1 """Support for FleetGO Platform."""
3 from __future__
import annotations
8 from ritassist
import API
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
27 _LOGGER = logging.getLogger(__name__)
29 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
31 vol.Required(CONF_USERNAME): cv.string,
32 vol.Required(CONF_PASSWORD): cv.string,
33 vol.Required(CONF_CLIENT_ID): cv.string,
34 vol.Required(CONF_CLIENT_SECRET): cv.string,
35 vol.Optional(CONF_INCLUDE, default=[]): vol.All(cv.ensure_list, [cv.string]),
44 discovery_info: DiscoveryInfoType |
None =
None,
46 """Set up the DeviceScanner and check if login is valid."""
48 if not scanner.login(hass):
49 _LOGGER.error(
"FleetGO authentication failed")
55 """Define a scanner for the FleetGO platform."""
57 def __init__(self, config, see: SeeCallback) ->
None:
58 """Initialize FleetGoDeviceScanner."""
59 self.
_include_include = config.get(CONF_INCLUDE)
63 config.get(CONF_CLIENT_ID),
64 config.get(CONF_CLIENT_SECRET),
65 config.get(CONF_USERNAME),
66 config.get(CONF_PASSWORD),
70 """Set up a timer and start gathering devices."""
73 hass,
lambda now: self.
_refresh_refresh(), second=range(0, 60, 30)
77 """Perform a login on the FleetGO API."""
84 """Refresh device information from the platform."""
86 devices = self.
_api_api.get_devices()
88 for device
in devices:
89 if not self.
_include_include
or device.license_plate
in self.
_include_include:
90 if device.active
or device.current_address
is None:
91 device.get_map_details()
94 dev_id=device.plate_as_id,
95 gps=(device.latitude, device.longitude),
96 attributes=device.state_attributes,
100 except requests.exceptions.ConnectionError:
101 _LOGGER.error(
"ConnectionError: Could not connect to FleetGO")
None __init__(self, config, SeeCallback see)
bool setup_scanner(HomeAssistant hass, ConfigType config, SeeCallback see, DiscoveryInfoType|None discovery_info=None)