Move imports to top for traccar (#29116)
parent
5eaafcfd7f
commit
33c6ee80ad
|
@ -1,14 +1,15 @@
|
|||
"""Support for Traccar."""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
from aiohttp import web
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import HTTP_UNPROCESSABLE_ENTITY, HTTP_OK, CONF_WEBHOOK_ID
|
||||
from homeassistant.helpers import config_entry_flow
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER
|
||||
from homeassistant.const import CONF_WEBHOOK_ID, HTTP_OK, HTTP_UNPROCESSABLE_ENTITY
|
||||
from homeassistant.helpers import config_entry_flow
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
from .const import (
|
||||
ATTR_ACCURACY,
|
||||
ATTR_ALTITUDE,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Config flow for Traccar."""
|
||||
from homeassistant.helpers import config_entry_flow
|
||||
from .const import DOMAIN
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
config_entry_flow.register_webhook_flow(
|
||||
DOMAIN,
|
||||
|
|
|
@ -2,29 +2,31 @@
|
|||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
from pytraccar.api import API
|
||||
from stringcase import camelcase
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
CONF_VERIFY_SSL,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_EVENT,
|
||||
)
|
||||
from homeassistant.components.device_tracker import PLATFORM_SCHEMA, SOURCE_TYPE_GPS
|
||||
from homeassistant.components.device_tracker.config_entry import TrackerEntity
|
||||
from homeassistant.const import (
|
||||
CONF_EVENT,
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import device_registry
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import DOMAIN, TRACKER_UPDATE
|
||||
|
@ -41,30 +43,29 @@ from .const import (
|
|||
ATTR_MOTION,
|
||||
ATTR_SPEED,
|
||||
ATTR_STATUS,
|
||||
ATTR_TRACKER,
|
||||
ATTR_TRACCAR_ID,
|
||||
EVENT_DEVICE_MOVING,
|
||||
EVENT_COMMAND_RESULT,
|
||||
EVENT_DEVICE_FUEL_DROP,
|
||||
EVENT_GEOFENCE_ENTER,
|
||||
EVENT_DEVICE_OFFLINE,
|
||||
EVENT_DRIVER_CHANGED,
|
||||
EVENT_GEOFENCE_EXIT,
|
||||
EVENT_DEVICE_OVERSPEED,
|
||||
EVENT_DEVICE_ONLINE,
|
||||
EVENT_DEVICE_STOPPED,
|
||||
EVENT_MAINTENANCE,
|
||||
EVENT_ALARM,
|
||||
EVENT_TEXT_MESSAGE,
|
||||
EVENT_DEVICE_UNKNOWN,
|
||||
EVENT_IGNITION_OFF,
|
||||
EVENT_IGNITION_ON,
|
||||
EVENT_ALL_EVENTS,
|
||||
ATTR_TRACKER,
|
||||
CONF_MAX_ACCURACY,
|
||||
CONF_SKIP_ACCURACY_ON,
|
||||
EVENT_ALARM,
|
||||
EVENT_ALL_EVENTS,
|
||||
EVENT_COMMAND_RESULT,
|
||||
EVENT_DEVICE_FUEL_DROP,
|
||||
EVENT_DEVICE_MOVING,
|
||||
EVENT_DEVICE_OFFLINE,
|
||||
EVENT_DEVICE_ONLINE,
|
||||
EVENT_DEVICE_OVERSPEED,
|
||||
EVENT_DEVICE_STOPPED,
|
||||
EVENT_DEVICE_UNKNOWN,
|
||||
EVENT_DRIVER_CHANGED,
|
||||
EVENT_GEOFENCE_ENTER,
|
||||
EVENT_GEOFENCE_EXIT,
|
||||
EVENT_IGNITION_OFF,
|
||||
EVENT_IGNITION_ON,
|
||||
EVENT_MAINTENANCE,
|
||||
EVENT_TEXT_MESSAGE,
|
||||
)
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_SCAN_INTERVAL = timedelta(seconds=30)
|
||||
|
@ -156,7 +157,6 @@ async def async_setup_entry(hass: HomeAssistantType, entry, async_add_entities):
|
|||
|
||||
async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
||||
"""Validate the configuration and return a Traccar scanner."""
|
||||
from pytraccar.api import API
|
||||
|
||||
session = async_get_clientsession(hass, config[CONF_VERIFY_SSL])
|
||||
|
||||
|
@ -199,7 +199,6 @@ class TraccarScanner:
|
|||
event_types,
|
||||
):
|
||||
"""Initialize."""
|
||||
from stringcase import camelcase
|
||||
|
||||
self._event_types = {camelcase(evt): evt for evt in event_types}
|
||||
self._custom_attributes = custom_attributes
|
||||
|
|
Loading…
Reference in New Issue