* De-run_forever()-ization
* Use asyncio.run (or our own implementation on Python <3.7)
* hass.start is only used by tests
* setup_and_run_hass() is now async
* Add "main" async hass.run method
* move SIGINT handling to helpers/signal.py
* add flag to .run to disable hass's signal handlers
* Teach async_start and async_stop to not step on each other
(more than necessary)
* shorten over-long lines
* restore missing "import asyncio"
* move run_asyncio to homeassistant.util.async_
* LOGGER: warn => warning
* Add "force" flag to async_stop
only useful for testing
* Add 'attrs==18.2.0' to requirements_all.txt
Required for keeping requirements_test_all.txt in sync, where it is in
turn required to prevent auto-downgrading "attrs" during "pip install"
* Fixes for mypy
* Fix "mock_signal" fixture
* Revert mistaken edit
* Flake8 fixes
* mypy fixes
* pylint fix
* Revert adding attrs== to requirements_test*.txt
solved by using "pip -c"
* Rename "run" to "async_run", as per calling conventions
* Don't treat typing as an "in-between" module for import order
That was a < 3.5 era thing.
* Tighten scope of some pylint unused-import disables
To avoid isort moving a top level one around, undesirably broadening its
scope.
## Description:
Make typing checks more strict: add `--strict-optional` flag that forbids implicit None return type. This flag will become default in the next version of mypy (0.600)
Add `homeassistant/util/` to checked dirs.
## Checklist:
- [x] The code change is tested and works locally.
- [x] Local tests pass with `tox`. **Your PR cannot be merged unless tests pass**
* Fix colorlog on windows
Modified the way logging is initialized to fix two things.
1. If the import of `colorlog` fails the logs will still be formatted
using the expected HASS log format.
2. Ensure that `logging.basicConfig` is called AFTER `colorlog` is
imported so that the default handler generated will be writing to the
wrapped stream generated when `colorama` is initialized. This allows
colored logging to work on Windows.
Added support for a `--log-no-color` command line switch in the event
that someone just wants to disable colored log output entirely.
* Fix line lengths
* Switch default value
* Fire EVENT_HOMEASSISTANT_START automations off right away while starting
* Actually have core state be set to 'starting' during boot
* Fix correct start implementation
* Test and deprecate event automation platform on start
* Fix doc strings
* Remove shutting down exception
* More strict when to mark an instance as finished
* Add automation platform to listen for start/shutdown
* When we stop we should wait till it's all done
* Fix testing
* Fix async bugs in tests
* Only set UVLOOP when hass starts from CLI
* This hangs normal asyncio event loop
* Clean up Z-Wave node entity test
* Fix hass script execution on Windows (#4977).
hass.exe returned ERRNO2 on a windows machine and must be started using
package loading. This fix adapts the command line options for
`setup_and_run_hass()` to start
either a script with `python homeassistant/__main__.py` or with
`Scripts/hass.exe`
* Fix code style
* Add event loop to the core
* Add block_till_done to HA core object
* Fix some tests
* Linting core
* Fix statemachine tests
* Core test fixes
* fix block_till_done to wait for loop and queue to empty
* fix test_core for passing, and correct start/stop/block_till_done
* Fix remote tests
* Fix tests: block_till_done
* Fix linting
* Fix more tests
* Fix final linting
* Fix remote test
* remove unnecessary import
* reduce sleep to avoid slowing down the tests excessively
* fix remaining tests to wait for non-threadsafe operations
* Add async_ doc strings for event loop / coroutine info
* Fix command line test to block for the right timeout
* Fix py3.4.2 loop var access
* Fix SERVICE_CALL_LIMIT being in effect for other tests
* Fix lint errors
* Fix lint error with proper placement
* Fix slave start to not start a timer
* Add asyncio compatible listeners.
* Increase min Python version to 3.4.2
* Move async backports to util
* Add backported async tests
* Fix linting
* Simplify Python version check
* Fix lint
* Remove unneeded try/except and queue listener appproriately.
* Fix tuple vs. list unorderable error on version compare.
* Fix version tests
* Fix: Circular dependencies of internal files
* Change: dt.date for Date and dt.datetime for DateTime
* Use NewType if available
* FIX: Wrong version test
* Remove: Date and DateTime types due to error
* Change to HomeAssistantType
* General Improvement of Typing
* Improve typing config_validation
* Improve typing script
* General Typing Improvements
* Improve NewType check
* Improve typing db_migrator
* Improve util/__init__ typing
* Improve helpers/location typing
* Regroup imports and remove pylint: disable=ungrouped-imports
* General typing improvements
* Add __main__ type hints
* Fix most errors of __main__
* Add ignore for script.run()
* Add type annotations for from_config_dict and from_config_file
* Fix errors
* Fix requirement error
* Add mypy type check to tests
* Enable travis typing check
* Messed up the tox deps
* Laxer type checker
While looking for leaked resources (threads) after shutdown and before restart
we in some cases get an assertion in the python threading module where we find
a thread marked as running at the python level but it has no associated thread
at the C level.
* Ignore permission errors on setpgid.
When launched in a docker container we got a permission denied error
from setpgid.
* Don't fail if we find our own pidfile.
When we restart using exec we are running a new instance of home-assistant with
the same process id so we shouldn't be surprised to find an existing pidfile in
that case.
* Allow restart to work when started as python -m homeassistant.
When we are started with `python -m homeassistant`, the restart command line
becomes `python /path/to/hass/homeassistant/__main__.py`. But in that case the
python path includes `/path/to/hass/homeassistant` instead of `/path/to/hass`
and we fail on the first import.
Fix this by recognizing `/__main__.py` as part of the first argument and
injecting the proper path as PYTHONPATH environment before we start the new
home-assistant instance.
* Allow for restart without using parent/child processes.
Assuming that we normally correctly shut down running threads and
release resources, we just do some minimal scrubbing of open file
descriptors and child processes which would stay around across an
exec() boundary.
* Use sys.executable instead of multiprocessing.spawn.get_executable()
* Limit how many file descriptors we try to close.
Don't even try to close on OSX/Darwin until we figure out how to
recognize guarded fds because the kernel will yell at us, and kill
the process.
* Use the close on exec flag on MacOS to clean up.
* Introduce a small process runner to handle restart on windows.
* Handle missing signal.SIGHUP on Windows.
1. Moved RESTART_EXIT_CODE to constants so it can safely be used by
__main__.py.
2. Allowed __main__/main to return the desired exit code.
3. Forwarded the child processes exit code to the parent process to be
duplicated.
4. Added —debug flag to pass command to force Home Assistant to run in
only one process. A warning is printed to STDERR to indicate HASS is in
debug mode. Another is printed if HASS requests a restart in debug
mode. A restart request in debug mode will quit.
5. Added an argument to __main__/main/setup_and_run_hass to indicate
that it is running in the top process. This tells it to return the exit
code rather than exiting.