Add elevation to as_dict and use unified style for quoting (#5448)

This commit is contained in:
Fabian Affolter 2017-01-20 08:55:29 +01:00 committed by Paulus Schoutsen
parent 1f6f9a1677
commit 2ed0e76e7c
2 changed files with 25 additions and 25 deletions

View File

@ -43,7 +43,7 @@ try:
except ImportError: except ImportError:
pass pass
DOMAIN = "homeassistant" DOMAIN = 'homeassistant'
# How often time_changed event should fire # How often time_changed event should fire
TIMER_INTERVAL = 1 # seconds TIMER_INTERVAL = 1 # seconds
@ -88,10 +88,10 @@ def is_callback(func: Callable[..., Any]) -> bool:
class CoreState(enum.Enum): class CoreState(enum.Enum):
"""Represent the current state of Home Assistant.""" """Represent the current state of Home Assistant."""
not_running = "NOT_RUNNING" not_running = 'NOT_RUNNING'
starting = "STARTING" starting = 'STARTING'
running = "RUNNING" running = 'RUNNING'
stopping = "STOPPING" stopping = 'STOPPING'
def __str__(self) -> str: def __str__(self) -> str:
"""Return the event.""" """Return the event."""
@ -103,7 +103,7 @@ class HomeAssistant(object):
def __init__(self, loop=None): def __init__(self, loop=None):
"""Initialize new Home Assistant object.""" """Initialize new Home Assistant object."""
if sys.platform == "win32": if sys.platform == 'win32':
self.loop = loop or asyncio.ProactorEventLoop() self.loop = loop or asyncio.ProactorEventLoop()
else: else:
self.loop = loop or asyncio.get_event_loop() self.loop = loop or asyncio.get_event_loop()
@ -164,13 +164,13 @@ class HomeAssistant(object):
self.loop.add_signal_handler( self.loop.add_signal_handler(
signal.SIGTERM, self._async_stop_handler) signal.SIGTERM, self._async_stop_handler)
except ValueError: except ValueError:
_LOGGER.warning('Could not bind to SIGTERM.') _LOGGER.warning("Could not bind to SIGTERM")
try: try:
self.loop.add_signal_handler( self.loop.add_signal_handler(
signal.SIGHUP, self._async_restart_handler) signal.SIGHUP, self._async_restart_handler)
except ValueError: except ValueError:
_LOGGER.warning('Could not bind to SIGHUP.') _LOGGER.warning("Could not bind to SIGHUP")
# pylint: disable=protected-access # pylint: disable=protected-access
self.loop._thread_ident = threading.get_ident() self.loop._thread_ident = threading.get_ident()
@ -185,7 +185,7 @@ class HomeAssistant(object):
args: parameters for method to call. args: parameters for method to call.
""" """
if target is None: if target is None:
raise ValueError("Don't call add_job with None.") raise ValueError("Don't call add_job with None")
self.loop.call_soon_threadsafe(self.async_add_job, target, *args) self.loop.call_soon_threadsafe(self.async_add_job, target, *args)
@callback @callback
@ -322,8 +322,7 @@ class HomeAssistant(object):
kwargs['exc_info'] = (type(exception), exception, kwargs['exc_info'] = (type(exception), exception,
exception.__traceback__) exception.__traceback__)
_LOGGER.error('Error doing job: %s', context['message'], _LOGGER.error("Error doing job: %s", context['message'], **kwargs)
**kwargs)
@callback @callback
def _async_stop_handler(self, *args): def _async_stop_handler(self, *args):
@ -341,8 +340,8 @@ class HomeAssistant(object):
class EventOrigin(enum.Enum): class EventOrigin(enum.Enum):
"""Represent the origin of an event.""" """Represent the origin of an event."""
local = "LOCAL" local = 'LOCAL'
remote = "REMOTE" remote = 'REMOTE'
def __str__(self): def __str__(self):
"""Return the event.""" """Return the event."""
@ -420,8 +419,8 @@ class EventBus(object):
def fire(self, event_type: str, event_data=None, origin=EventOrigin.local): def fire(self, event_type: str, event_data=None, origin=EventOrigin.local):
"""Fire an event.""" """Fire an event."""
self._hass.loop.call_soon_threadsafe(self.async_fire, event_type, self._hass.loop.call_soon_threadsafe(
event_data, origin) self.async_fire, event_type, event_data, origin)
@callback @callback
def async_fire(self, event_type: str, event_data=None, def async_fire(self, event_type: str, event_data=None,
@ -432,7 +431,7 @@ class EventBus(object):
""" """
if event_type != EVENT_HOMEASSISTANT_STOP and \ if event_type != EVENT_HOMEASSISTANT_STOP and \
self._hass.state == CoreState.stopping: self._hass.state == CoreState.stopping:
raise ShuttingDown('Home Assistant is shutting down.') raise ShuttingDown("Home Assistant is shutting down")
# Copy the list of the current listeners because some listeners # Copy the list of the current listeners because some listeners
# remove themselves as a listener while being executed which # remove themselves as a listener while being executed which
@ -549,8 +548,7 @@ class EventBus(object):
except (KeyError, ValueError): except (KeyError, ValueError):
# KeyError is key event_type listener did not exist # KeyError is key event_type listener did not exist
# ValueError if listener did not exist within event_type # ValueError if listener did not exist within event_type
_LOGGER.warning('Unable to remove unknown listener %s', _LOGGER.warning("Unable to remove unknown listener %s", listener)
listener)
class State(object): class State(object):
@ -995,14 +993,14 @@ class ServiceRegistry(object):
if event.data[ATTR_SERVICE_CALL_ID] == call_id: if event.data[ATTR_SERVICE_CALL_ID] == call_id:
fut.set_result(True) fut.set_result(True)
unsub = self._hass.bus.async_listen(EVENT_SERVICE_EXECUTED, unsub = self._hass.bus.async_listen(
service_executed) EVENT_SERVICE_EXECUTED, service_executed)
self._hass.bus.async_fire(EVENT_CALL_SERVICE, event_data) self._hass.bus.async_fire(EVENT_CALL_SERVICE, event_data)
if blocking: if blocking:
done, _ = yield from asyncio.wait([fut], loop=self._hass.loop, done, _ = yield from asyncio.wait(
timeout=SERVICE_CALL_LIMIT) [fut], loop=self._hass.loop, timeout=SERVICE_CALL_LIMIT)
success = bool(done) success = bool(done)
unsub() unsub()
return success return success
@ -1017,7 +1015,7 @@ class ServiceRegistry(object):
if not self.has_service(domain, service): if not self.has_service(domain, service):
if event.origin == EventOrigin.local: if event.origin == EventOrigin.local:
_LOGGER.warning('Unable to find service %s/%s', _LOGGER.warning("Unable to find service %s/%s",
domain, service) domain, service)
return return
@ -1040,7 +1038,7 @@ class ServiceRegistry(object):
if service_handler.schema: if service_handler.schema:
service_data = service_handler.schema(service_data) service_data = service_handler.schema(service_data)
except vol.Invalid as ex: except vol.Invalid as ex:
_LOGGER.error('Invalid service data for %s.%s: %s', _LOGGER.error("Invalid service data for %s.%s: %s",
domain, service, humanize_error(service_data, ex)) domain, service, humanize_error(service_data, ex))
fire_service_executed() fire_service_executed()
return return
@ -1064,7 +1062,7 @@ class ServiceRegistry(object):
def _generate_unique_id(self): def _generate_unique_id(self):
"""Generate a unique service call id.""" """Generate a unique service call id."""
self._cur_id += 1 self._cur_id += 1
return "{}-{}".format(id(self), self._cur_id) return '{}-{}'.format(id(self), self._cur_id)
class Config(object): class Config(object):
@ -1118,6 +1116,7 @@ class Config(object):
return { return {
'latitude': self.latitude, 'latitude': self.latitude,
'longitude': self.longitude, 'longitude': self.longitude,
'elevation': self.elevation,
'unit_system': self.units.as_dict(), 'unit_system': self.units.as_dict(),
'location_name': self.location_name, 'location_name': self.location_name,
'time_zone': time_zone.zone, 'time_zone': time_zone.zone,

View File

@ -724,6 +724,7 @@ class TestConfig(unittest.TestCase):
expected = { expected = {
'latitude': None, 'latitude': None,
'longitude': None, 'longitude': None,
'elevation': None,
CONF_UNIT_SYSTEM: METRIC_SYSTEM.as_dict(), CONF_UNIT_SYSTEM: METRIC_SYSTEM.as_dict(),
'location_name': None, 'location_name': None,
'time_zone': 'UTC', 'time_zone': 'UTC',