mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
commit
644d5de890
@ -4,7 +4,6 @@ from __future__ import print_function
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import signal
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
@ -334,29 +333,6 @@ def try_to_restart():
|
|||||||
except AssertionError:
|
except AssertionError:
|
||||||
sys.stderr.write("Failed to count non-daemonic threads.\n")
|
sys.stderr.write("Failed to count non-daemonic threads.\n")
|
||||||
|
|
||||||
# Send terminate signal to all processes in our process group which
|
|
||||||
# should be any children that have not themselves changed the process
|
|
||||||
# group id. Don't bother if couldn't even call setpgid.
|
|
||||||
if hasattr(os, 'setpgid'):
|
|
||||||
sys.stderr.write("Signalling child processes to terminate...\n")
|
|
||||||
os.kill(0, signal.SIGTERM)
|
|
||||||
|
|
||||||
# wait for child processes to terminate
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
time.sleep(1)
|
|
||||||
if os.waitpid(0, os.WNOHANG) == (0, 0):
|
|
||||||
break
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
elif os.name == 'nt':
|
|
||||||
# Maybe one of the following will work, but how do we indicate which
|
|
||||||
# processes are our children if there is no process group?
|
|
||||||
# os.kill(0, signal.CTRL_C_EVENT)
|
|
||||||
# os.kill(0, signal.CTRL_BREAK_EVENT)
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Try to not leave behind open filedescriptors with the emphasis on try.
|
# Try to not leave behind open filedescriptors with the emphasis on try.
|
||||||
try:
|
try:
|
||||||
max_fd = os.sysconf("SC_OPEN_MAX")
|
max_fd = os.sysconf("SC_OPEN_MAX")
|
||||||
@ -408,13 +384,6 @@ def main():
|
|||||||
if args.pid_file:
|
if args.pid_file:
|
||||||
write_pid(args.pid_file)
|
write_pid(args.pid_file)
|
||||||
|
|
||||||
# Create new process group if we can
|
|
||||||
if hasattr(os, 'setpgid'):
|
|
||||||
try:
|
|
||||||
os.setpgid(0, 0)
|
|
||||||
except PermissionError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
exit_code = setup_and_run_hass(config_dir, args)
|
exit_code = setup_and_run_hass(config_dir, args)
|
||||||
if exit_code == RESTART_EXIT_CODE and not args.runner:
|
if exit_code == RESTART_EXIT_CODE and not args.runner:
|
||||||
try_to_restart()
|
try_to_restart()
|
||||||
|
@ -136,10 +136,11 @@ class GoogleTravelTimeSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
try:
|
_data = self._matrix['rows'][0]['elements'][0]
|
||||||
res = self._matrix['rows'][0]['elements'][0]['duration']['value']
|
if 'duration_in_traffic' in _data:
|
||||||
return round(res/60)
|
return round(_data['duration_in_traffic']['value']/60)
|
||||||
except KeyError:
|
if 'duration' in _data:
|
||||||
|
return round(_data['duration']['value']/60)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -175,9 +176,15 @@ class GoogleTravelTimeSensor(Entity):
|
|||||||
atime = options_copy.get('arrival_time')
|
atime = options_copy.get('arrival_time')
|
||||||
if dtime is not None and ':' in dtime:
|
if dtime is not None and ':' in dtime:
|
||||||
options_copy['departure_time'] = convert_time_to_utc(dtime)
|
options_copy['departure_time'] = convert_time_to_utc(dtime)
|
||||||
|
elif dtime is not None:
|
||||||
|
options_copy['departure_time'] = dtime
|
||||||
|
else:
|
||||||
|
options_copy['departure_time'] = 'now'
|
||||||
|
|
||||||
if atime is not None and ':' in atime:
|
if atime is not None and ':' in atime:
|
||||||
options_copy['arrival_time'] = convert_time_to_utc(atime)
|
options_copy['arrival_time'] = convert_time_to_utc(atime)
|
||||||
|
elif atime is not None:
|
||||||
|
options_copy['arrival_time'] = atime
|
||||||
|
|
||||||
self._matrix = self._client.distance_matrix(self._origin,
|
self._matrix = self._client.distance_matrix(self._origin,
|
||||||
self._destination,
|
self._destination,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
"""Constants used by Home Assistant components."""
|
"""Constants used by Home Assistant components."""
|
||||||
|
|
||||||
__version__ = "0.20.1"
|
__version__ = "0.20.2"
|
||||||
REQUIRED_PYTHON_VER = (3, 4)
|
REQUIRED_PYTHON_VER = (3, 4)
|
||||||
|
|
||||||
PLATFORM_FORMAT = '{}.{}'
|
PLATFORM_FORMAT = '{}.{}'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user