From 229d19bb20f4fc318c784517c667b92ca99f38fd Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen <paulus@home-assistant.io> Date: Wed, 27 Feb 2019 21:35:14 -0800 Subject: [PATCH] Fix lint (#21520) --- homeassistant/components/person/__init__.py | 21 +++++++++++--------- homeassistant/components/sensor/airvisual.py | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/person/__init__.py b/homeassistant/components/person/__init__.py index c4af4a699cd..622ca0608ac 100644 --- a/homeassistant/components/person/__init__.py +++ b/homeassistant/components/person/__init__.py @@ -2,6 +2,7 @@ from collections import OrderedDict from itertools import chain import logging +from typing import Optional import uuid import voluptuous as vol @@ -13,7 +14,7 @@ from homeassistant.const import ( ATTR_ID, ATTR_LATITUDE, ATTR_LONGITUDE, ATTR_GPS_ACCURACY, CONF_ID, CONF_NAME, EVENT_HOMEASSISTANT_START, STATE_UNKNOWN, STATE_UNAVAILABLE, STATE_HOME, STATE_NOT_HOME) -from homeassistant.core import callback, Event +from homeassistant.core import callback, Event, State from homeassistant.auth import EVENT_USER_REMOVED import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_component import EntityComponent @@ -377,11 +378,6 @@ class Person(RestoreEntity): """Handle the device tracker state changes.""" self._update_state() - def _get_latest(self, prev, curr): - return curr \ - if prev is None or curr.last_updated > prev.last_updated \ - else prev - @callback def _update_state(self): """Update the state.""" @@ -393,11 +389,11 @@ class Person(RestoreEntity): continue if state.attributes.get(ATTR_SOURCE_TYPE) == SOURCE_TYPE_GPS: - latest_gps = self._get_latest(latest_gps, state) + latest_gps = _get_latest(latest_gps, state) elif state.state == STATE_HOME: - latest_home = self._get_latest(latest_home, state) + latest_home = _get_latest(latest_home, state) elif state.state == STATE_NOT_HOME: - latest_not_home = self._get_latest(latest_not_home, state) + latest_not_home = _get_latest(latest_not_home, state) if latest_home: latest = latest_home @@ -508,3 +504,10 @@ async def ws_delete_person(hass: HomeAssistantType, manager = hass.data[DOMAIN] # type: PersonManager await manager.async_delete_person(msg['person_id']) connection.send_result(msg['id']) + + +def _get_latest(prev: Optional[State], curr: State): + """Get latest state.""" + if prev is None or curr.last_updated > prev.last_updated: + return curr + return prev diff --git a/homeassistant/components/sensor/airvisual.py b/homeassistant/components/sensor/airvisual.py index 46457a17ebb..e13fb924041 100644 --- a/homeassistant/components/sensor/airvisual.py +++ b/homeassistant/components/sensor/airvisual.py @@ -141,7 +141,7 @@ async def async_setup_platform( "Using city, state, and country: %s, %s, %s", city, state, country) location_id = ','.join((city, state, country)) data = AirVisualData( - Client(config[CONF_API_KEY], websession), + Client(websession, api_key=config[CONF_API_KEY]), city=city, state=state, country=country, @@ -152,7 +152,7 @@ async def async_setup_platform( "Using latitude and longitude: %s, %s", latitude, longitude) location_id = ','.join((str(latitude), str(longitude))) data = AirVisualData( - Client(config[CONF_API_KEY], websession), + Client(websession, api_key=config[CONF_API_KEY]), latitude=latitude, longitude=longitude, show_on_map=config[CONF_SHOW_ON_MAP], -- GitLab