parent
ce6911a471
commit
a78b5413b1
@ -0,0 +1,5 @@
|
|||||||
|
#python venv
|
||||||
|
lib64/
|
||||||
|
bin/
|
||||||
|
include/
|
||||||
|
lib/
|
@ -0,0 +1,3 @@
|
|||||||
|
language: python
|
||||||
|
python:
|
||||||
|
- "3.7"
|
@ -1,72 +1,116 @@
|
|||||||
|
""" georide custom conpennt """
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from georideapilib.objects import GeorideAccount
|
from georideapilib.objects import GeorideAccount
|
||||||
import georideapilib.api as GeorideApi
|
import georideapilib.api as GeorideApi
|
||||||
|
|
||||||
|
import logging
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.const import CONF_WEBHOOK_ID
|
||||||
|
from homeassistant.core import callback
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.setup import async_when_setup
|
||||||
|
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = "georide"
|
DOMAIN = "georide"
|
||||||
CONF_EMAIL = "email"
|
CONF_EMAIL = "email"
|
||||||
CONF_PASSWORD = "password"
|
CONF_PASSWORD = "password"
|
||||||
|
|
||||||
|
TRACKER_ID = "trackerId"
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(DOMAIN, default={}): {
|
vol.Required(DOMAIN, default={}): {
|
||||||
vol.Required(CONF_EMAIL): vol.All(str, Length(min=3)),
|
vol.Required(CONF_EMAIL): vol.All(str, vol.Length(min=3)),
|
||||||
vol.Required(CONF_PASSWORD): vol.All(str)
|
vol.Required(CONF_PASSWORD): vol.All(str)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
|
||||||
"""Initialize OwnTracks component."""
|
def setup(hass, config):
|
||||||
|
"""Initialize Georide component."""
|
||||||
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
|
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
|
||||||
if not hass.config_entries.async_entries(DOMAIN):
|
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.flow.async_init(
|
hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
|
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_LOGGER.info("Georide-setup ")
|
||||||
|
|
||||||
|
|
||||||
|
# Return boolean to indicate that initialization was successful.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
|
||||||
"""Set up Georide entry."""
|
|
||||||
config = hass.data[DOMAIN]["config"]
|
|
||||||
email = config.get(CONF_EMAIL)
|
|
||||||
password = config.get(CONF_PASSWORD)
|
|
||||||
trackerId = config.get(CONF_TRACKER_ID)
|
|
||||||
token = config.get(CONF_TOKEN)
|
|
||||||
|
|
||||||
context = GeorideContext(
|
|
||||||
hass,
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
trackerId,
|
|
||||||
token
|
|
||||||
)
|
|
||||||
|
|
||||||
webhook_id = config.get(CONF_WEBHOOK_ID) or entry.data[CONF_WEBHOOK_ID]
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
class GeorideContext:
|
class GeorideContext:
|
||||||
"""Hold the current Georide context."""
|
"""Hold the current Georide context."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, hass, email, password):
|
||||||
hass,
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
trackerId,
|
|
||||||
token
|
|
||||||
):
|
|
||||||
"""Initialize an Georide context."""
|
"""Initialize an Georide context."""
|
||||||
self.hass = hass
|
self._hass = hass
|
||||||
self.email = email
|
self._email = email
|
||||||
self.password = password
|
self._password = password
|
||||||
self.trackerId = trackerId
|
self._georide_trackers = defaultdict(set)
|
||||||
self.token = token
|
self._token = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hass(self):
|
||||||
|
""" hass """
|
||||||
|
return self._hass
|
||||||
|
|
||||||
|
@property
|
||||||
|
def email(self):
|
||||||
|
""" current email """
|
||||||
|
return self._email
|
||||||
|
|
||||||
|
@property
|
||||||
|
def password(self):
|
||||||
|
""" password """
|
||||||
|
return self._password
|
||||||
|
|
||||||
|
@property
|
||||||
|
def token(self):
|
||||||
|
""" current jwt token """
|
||||||
|
return self._token
|
||||||
|
|
||||||
|
@property
|
||||||
|
def georide_trackers(self):
|
||||||
|
""" georide tracker list """
|
||||||
|
return self._georide_trackers
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_see_beacons(self, hass, dev_id, kwargs_param):
|
||||||
|
"""Set active beacons to the current location."""
|
||||||
|
kwargs = kwargs_param.copy()
|
||||||
|
|
||||||
|
# Mobile beacons should always be set to the location of the
|
||||||
|
# tracking device. I get the device state and make the necessary
|
||||||
|
# changes to kwargs.
|
||||||
|
device_tracker_state = hass.states.get(f"device_tracker.{dev_id}")
|
||||||
|
|
||||||
|
if device_tracker_state is not None:
|
||||||
|
lat = device_tracker_state.attributes.get("latitude")
|
||||||
|
lon = device_tracker_state.attributes.get("longitude")
|
||||||
|
|
||||||
|
if lat is not None and lon is not None:
|
||||||
|
kwargs["gps"] = (lat, lon)
|
||||||
|
else:
|
||||||
|
kwargs["gps"] = None
|
||||||
|
|
||||||
|
for tracker in self.georide_trackers[dev_id]:
|
||||||
|
kwargs["dev_id"] = f"{TRACKER_ID}_{tracker}"
|
||||||
|
kwargs["host_name"] = tracker
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
""" device tracker for Georide object """
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from homeassistant.core import callback
|
|
||||||
from homeassistant.const import (
|
|
||||||
ATTR_GPS_ACCURACY,
|
|
||||||
ATTR_LATITUDE,
|
|
||||||
ATTR_LONGITUDE,
|
|
||||||
ATTR_BATTERY_LEVEL,
|
|
||||||
)
|
|
||||||
|
|
||||||
from homeassistant.components.device_tracker.const import (
|
|
||||||
ENTITY_ID_FORMAT,
|
|
||||||
ATTR_SOURCE_TYPE,
|
|
||||||
SOURCE_TYPE_GPS,
|
|
||||||
)
|
|
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"domain": "georide",
|
||||||
|
"name": "Georide",
|
||||||
|
"config_flow": false,
|
||||||
|
"documentation": "https://git.tontontux.fr/mduval/GeorideHA",
|
||||||
|
"requirements": [
|
||||||
|
"georideapilib==0.1.0"
|
||||||
|
],
|
||||||
|
"dependencies": [
|
||||||
|
"urllib3",
|
||||||
|
],
|
||||||
|
"codeowners": ["ptimatth"]
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Georide integration",
|
"name": "Georide integration",
|
||||||
"content_in_root": true,
|
"content_in_root": false,
|
||||||
"rener_readme": true,
|
"render_readme": true,
|
||||||
"domains": ["devices_tracker", "sensor"],
|
"domains": ["devices_tracker", "sensor"],
|
||||||
"country": ["FR"]
|
"country": ["FR"]
|
||||||
}
|
}
|
Loading…
Reference in new issue