Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ omit =
homeassistant/components/device_tracker/tile.py
homeassistant/components/device_tracker/tomato.py
homeassistant/components/device_tracker/tplink.py
homeassistant/components/device_tracker/traccar.py
homeassistant/components/device_tracker/trackr.py
homeassistant/components/device_tracker/ubus.py
homeassistant/components/downloader.py
Expand Down
90 changes: 90 additions & 0 deletions homeassistant/components/device_tracker/traccar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
Support for Traccar device tracking.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.traccar/
"""
from datetime import timedelta
import logging

import voluptuous as vol

from homeassistant.components.device_tracker import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_HOST, CONF_PORT, CONF_SSL, CONF_VERIFY_SSL,
CONF_PASSWORD, CONF_USERNAME)
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


REQUIREMENTS = ['pytraccar==0.1.2']

_LOGGER = logging.getLogger(__name__)

ATTR_ADDRESS = 'address'
ATTR_CATEGORY = 'category'
ATTR_GEOFENCE = 'geofence'
ATTR_TRACKER = 'tracker'

DEFAULT_SCAN_INTERVAL = timedelta(seconds=30)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT, default=8082): cv.port,
vol.Optional(CONF_SSL, default=False): cv.boolean,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that we are using a secured channel for the communication by default, if possible.

Copy link
Copy Markdown
Member Author

@ludeeus ludeeus Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible, but I think that would confuse the potential enduser?
Home Assistant itself and most of the components/platforms do have this as false by defaul?

git grep "CONF_SSL, default=True"
homeassistant/components/sensor/synologydsm.py:    vol.Optional(CONF_SSL, default=True): cv.boolean,
git grep "CONF_SSL, default=False"
homeassistant/components/binary_sensor/hikvision.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/device_tracker/netgear.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/device_tracker/tomato.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/device_tracker/traccar.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/media_player/epson.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/octoprint.py:        vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/sensor/nzbget.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/sensor/pyload.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/sensor/qnap.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/sensor/radarr.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/sensor/sma.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/sensor/sonarr.py:    vol.Optional(CONF_SSL, default=False): cv.boolean,
homeassistant/components/splunk.py:        vol.Optional(CONF_SSL, default=False): cv.boolean,
git grep "DEFAULT_SSL ="
homeassistant/components/binary_sensor/concord232.py:DEFAULT_SSL = False
homeassistant/components/binary_sensor/nx584.py:DEFAULT_SSL = False
homeassistant/components/climate/venstar.py:DEFAULT_SSL = False
homeassistant/components/device_tracker/ddwrt.py:DEFAULT_SSL = False
homeassistant/components/device_tracker/luci.py:DEFAULT_SSL = False
homeassistant/components/media_player/emby.py:DEFAULT_SSL = False
homeassistant/components/media_player/firetv.py:DEFAULT_SSL = False
homeassistant/components/media_player/itunes.py:DEFAULT_SSL = False
homeassistant/components/rainmachine/__init__.py:DEFAULT_SSL = True
homeassistant/components/sabnzbd.py:DEFAULT_SSL = False
homeassistant/components/sensor/influxdb.py:DEFAULT_SSL = False
homeassistant/components/sensor/mfi.py:DEFAULT_SSL = True
homeassistant/components/sensor/pi_hole.py:DEFAULT_SSL = False
homeassistant/components/sensor/plex.py:DEFAULT_SSL = False
homeassistant/components/sensor/tautulli.py:DEFAULT_SSL = False
homeassistant/components/splunk.py:DEFAULT_SSL = False
homeassistant/components/switch/mfi.py:DEFAULT_SSL = True
homeassistant/components/zabbix.py:DEFAULT_SSL = False
homeassistant/components/zoneminder/__init__.py:DEFAULT_SSL = False

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not disagree with the suggestion, but to my knowledge, there is not a standard that a component or a platform should have that enabled by default, it may be something to discuss in https://github.com/home-assistant/architecture?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes a difference where the target is located. Devices on the LAN usually do not have valid certificates anyway.

Connections to servers on the internet should default to SSL with verification.

Copy link
Copy Markdown
Member Author

@ludeeus ludeeus Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if their paid service is running SSL, but the demo versions are not.
For the local version they do not have built-in support for SSL, you would have to run it behind a proxy to get that for a local instance.
I have used a local instance (hassio add-on) while building and testing this.

vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
})


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])

api = API(hass.loop, session, config[CONF_USERNAME], config[CONF_PASSWORD],
config[CONF_HOST], config[CONF_PORT], config[CONF_SSL])
scanner = TraccarScanner(api, hass, async_see)
return await scanner.async_init()


class TraccarScanner:
"""Define an object to retrieve Traccar data."""

def __init__(self, api, hass, async_see):
"""Initialize."""
self._async_see = async_see
self._api = api
self._hass = hass

async def async_init(self):
"""Further initialize connection to Traccar."""
await self._api.test_connection()
if self._api.authenticated:
await self._async_update()
async_track_time_interval(self._hass,
self._async_update,
DEFAULT_SCAN_INTERVAL)

return self._api.authenticated

async def _async_update(self, now=None):
"""Update info from Traccar."""
_LOGGER.debug('Updating device data.')
await self._api.get_device_info()
for devicename in self._api.device_info:
device = self._api.device_info[devicename]
device_attributes = {
ATTR_ADDRESS: device['address'],
ATTR_GEOFENCE: device['geofence'],
ATTR_CATEGORY: device['category'],
ATTR_TRACKER: 'traccar'
}
await self._async_see(
dev_id=slugify(device['device_id']),
gps=(device['latitude'], device['longitude']),
attributes=device_attributes)
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,9 @@ pytile==2.0.2
# homeassistant.components.climate.touchline
pytouchline==0.7

# homeassistant.components.device_tracker.traccar
pytraccar==0.1.2

# homeassistant.components.device_tracker.trackr
pytrackr==0.0.5

Expand Down