* Remove unneeded returns from handle_update() * Start __init__() params with hass. * Remove excess logging and downgrade remaining logging. * Remove period from end of comment * Decorate callback with @callback * Use more descriptive variables than key and value. * Inherit from BinarySensorDevice and overwrite is_on rather than state. * Removed uncheckedreturn values. * Use super() rather than explicit object. * Use add_entities instead of add_devices. * Don't use listener when calling immediately. * Remove some excess logging. * Switch to sync since pycarwings2 is sync. * Remove RuntimeError exception matching. * Add temporary reviewer comments. * Add UI help descriptions for update service. * Fix hound errors. * Replaced time.sleep() with await asyncio.sleep() * Removed location_updateon_on attribute since on device_tracker. * Use async_added_to_hass() and async_dispatcher_connect(). * Use dict[key] because schema key is required. * Clarify variable names. * Remove icon for charging switch. * Convert LeafChargeSwitch into service and sensor. * Use async_dispatcher_send(). * Add guard checks for discovery_info. Consistent logs. * Use async_schedul_update_ha_state(). * Device tracker should return true. * Remove icon for climate control. * Really remove icon for climate control. * Use register() instead of async_register(). * Add guard on device tracker if discovery_info is None.
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""Support for tracking a Nissan Leaf."""
|
|
import logging
|
|
|
|
from homeassistant.components.nissan_leaf import (
|
|
DATA_LEAF, DATA_LOCATION, SIGNAL_UPDATE_LEAF)
|
|
from homeassistant.helpers.dispatcher import dispatcher_connect
|
|
from homeassistant.util import slugify
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
DEPENDENCIES = ['nissan_leaf']
|
|
|
|
ICON_CAR = "mdi:car"
|
|
|
|
|
|
def setup_scanner(hass, config, see, discovery_info=None):
|
|
"""Set up the Nissan Leaf tracker."""
|
|
if discovery_info is None:
|
|
return False
|
|
|
|
def see_vehicle():
|
|
"""Handle the reporting of the vehicle position."""
|
|
for vin, datastore in hass.data[DATA_LEAF].items():
|
|
host_name = datastore.leaf.nickname
|
|
dev_id = 'nissan_leaf_{}'.format(slugify(host_name))
|
|
if not datastore.data[DATA_LOCATION]:
|
|
_LOGGER.debug("No position found for vehicle %s", vin)
|
|
return
|
|
_LOGGER.debug("Updating device_tracker for %s with position %s",
|
|
datastore.leaf.nickname,
|
|
datastore.data[DATA_LOCATION].__dict__)
|
|
attrs = {
|
|
'updated_on': datastore.last_location_response,
|
|
}
|
|
see(dev_id=dev_id,
|
|
host_name=host_name,
|
|
gps=(
|
|
datastore.data[DATA_LOCATION].latitude,
|
|
datastore.data[DATA_LOCATION].longitude
|
|
),
|
|
attributes=attrs,
|
|
icon=ICON_CAR)
|
|
|
|
dispatcher_connect(hass, SIGNAL_UPDATE_LEAF, see_vehicle)
|
|
|
|
return True
|