* awair: do not choke on no data
The awair API returns an empty response for various air data queries
when a device is offline. The underlying library (python_awair) does
not directly inform us that a device is offline, since we really can
only infer it from an empty response - there is no online/offline
indicator in the graphql API.
So - we should just ensure that we do not attempt to update device state
from an empty response. This ensures that the platform does not crash
when starting up with offline devices, and also ensures that the
platform is marked unavailable once devices go offline.
* Fix typo
Further proof that coding after 10pm is rolling the dice.
* some minor tests refactor
* async/await refactor
* toggle have not brightness
* test for race condition in unknown device
* test for 'no_command' and 'not_connected'
* test for race condition in unknown device
* sensor events are handled in sensor devices, RflinkDevice handle
command events
* test race conditions & bogus entity remove
* two more tests
* Test race condition for unknown components
* Test cleanup for `commands events` and `sensor events`
* Remove timer logic from sensor class
Proposed fix for issue #10500
* Updating the tests to remove timer logic
* Removing unecessary dependancy
* Fixing requested changes
* Commit to try to fix the CLA ?
* added new sensor platform to expose Islamic prayer times
* added new sensor platform to expose Islamic prayer times
* updated tests according to feedback
* make prayer_times_info a public attribute
* remove stale comments
* Added Entur departure information sensor.
* Fixed houndci-bot comments.
* Removed tailing whitespace.
* Fixed some comments from tox lint.
* Improved docstring, i think.
* Fix for C1801
* Unit test for entur platform setup
* Rewritten entur component to have pypi dependecy.
* Propper client id for api usage.
* Minor cleanup of usage of constants.
* Made location output configurable.
* Cleaned up usage of constants.
* Moved logic to be contained within setup or update methods.
* Moved icon consts to root in module.
* Using config directly in test
* Minor changes
* Fix statistics for binary sensor
-) Binary sensors have 'on' and 'off' for state resulting in issue as numbers were expected. Fixed so that it works with non-numeric states as well.
-) Added check to skip unknown states.
-) Updates test so that binary sensor test will use non-numeric values for states.
* Using guard clause and changed debug to error
Changed to use a guard clause for state unknown.
Writing error on value error instead of debug.
* Add docstring
* Awair Sensor Platform
This commit adds a sensor platform for Awair devices, by accessing
their beta API. Awair heavily rate-limits this API, so we throttle
updates based on the number of devices found. We also allow for the
user to bypass API device listing entirely, because the device list
endpoint is limited to only 6 calls per day. A crashing or restarting
server would quickly hit that limit.
This sensor platform uses the python_awair library (also written
as part of this PR), which is available for async usage.
* Disable pylint warning for broad try/catch
It's true that this is generally not a great idea, but we really don't
want to crash here. If we can't set up the platform, logging it and
continuing is the right answer.
* Add space to satisfy the linter
* Awair platform PR feedback
- Bump python_awair to 0.0.2, which has support for more granular exceptions
- Ensure we have python_awair available in test
- Raise PlatformNotReady if we can't set up Awair
- Make the 'Awair score' its own sensor, rather than exposing it other ways
- Set the platform up as polling, and set a sensible default
- Pass in throttling parameters to the underlying data class, rather
than use hacky global variable access to dynamically set the interval
- Switch to dict access for required variables
- Use pytest coroutines, set up components via async_setup_component,
and test/modify/assert in generally better ways
- Commit test data as fixtures
* Awair PR feedback, volume 2
- Don't force updates in test, instead modify time itself and let
homeassistant update things "normally".
- Remove unneeded polling attribute
- Rename timestamp attribute to 'last_api_update', to better reflect
that it is the timestamp of the last time the Awair API servers
received data from this device.
- Use that attribute to flag the component as unavailable when data
is stale. My own Awair device periodically goes offline and it really
hardly indicates that at all.
- Dynamically set fixture timestamps to the test run utcnow() value,
so that we don't have to worry about ancient timestamps in tests
blowing up down the line.
- Don't assert on entities directly, for the most part. Find desired
attributes in ... the attributes dict.
* Patch an instance of utcnow I overlooked
* Switch to using a context manager for timestream modification
Honestly, it's just a lot easier to keep track of patches. Moreover,
the ones I seem to have missed are now caught, and tests seem to
consistently pass.
Also, switch test_throttle_async_update to manipulating time more
explicitly.
* Missing blank line, thank you hound
* Fix pydocstyle error
I very much need to set up a script to do this quickly w/o tox, because
running flake8 is not enough!
* PR feedback
* PR feedback
Dark Sky Sensor didn't expose conditions for day 0 (today forecast) that
had the same name as current conditions. With this change all conditions
form day 0 (today) forecast are exposed the same way as conditions for
the rest of the days (1..7): as `dark_sky_<condition>_<day>`. As a
consequence, conditions for day 0 that were already exposed now have
`_0` suffix. This actually improves the code by removing most of
special handling, based on condition name.
To get day 0 conditions the user now has to add `- 0` to `forecast`
configuration parameter.
Conditions, for which suffix `_0` appeared: `precip_accumulation`,
`temperature_high`, `temperature_low`, `apparent_temperature_high`,
`apparent_temperature_low`, `precip_intensity_max`, `moon_phase`.
This is a breaking change!
Closes#18205
* Update query to include maxAge
Updated the query from recorded to include MaxAge if set; reducing the amount of records retrieved that would otherwise be purged anyway for the sensor.
* Initialization upon HASS start
Register the state listener and read previous information from recorder once HASS is started.
* Updated test_statistics.py for HASS start
Updated test_statistics.py to start HASS and wait it is completed before running test.
* Added newline in docstring
Added newline in docstring.
* Added start of HASS to test_initialize_from_database_with_maxage
Added start of HASS to new test test_initialize_from_database_with_maxage.
* Updates based on review
Following updates based on review:
-) Removed self._hass and passing hass
-) Changed async_add_job to async_create_task
-) For state update, calling async_schedule_update_ha_state
* Update query to include maxAge
Updated the query from recorded to include MaxAge if set; reducing the amount of records retrieved that would otherwise be purged anyway for the sensor.
* Added newline in docstring
Added newline in docstring.
* Add test + small fix
Added test to ensure query works correctly
Query should be greater then or equal instead of greater then. Fixed.
* Fixed lint issue
Fixed lint issue.
* Add srp_energy
* Update message on TypeError. Add check for None state.
* Add check for none in history
* Add srpenergy to Test requirements.
* Add srpenergy to requirments.
* Change = to ==.
* Change import for srpenergy
* Fix Flak8 errors
* Add srp to gen requirements script
* Change config name.
* Add daily usage test
* Add test for daily usage.
* Fix Flake8 message.
* Remove blank after docstring.
* Add srpenergy to coverage
* Bump requires version to srpenergy
* Fix type in coverage. Import from Sensor. Use dict.
* Update to 1.0.5. Check credentials on setup. Standalone test.
* Fix formating.
* Remove period. Rename _ variables.
* Fix rebase merge
* Add rebase requirement
* Improve Mock Patching.
In 0.7.x the API to HDate was cleaned up so as to move logic from homeassistant to
the HDate external library.
This commit removes all the superfluous code, updates the required tests and changes the
requirement from version 0.6.5 to 0.7.5
* Change date at sunset
* Fix tests to actually run and add fix to component
* Make tests pass
* Use get_astral_event_next instead of get_astral_event_date
* Revert to using get_astral_event_date
* Make tox happy: reset state on tearDown
* Initial changes to resolve issue 16733
Added logic to ensure that if the state is unknown during startup that the error about being unable to parse the value is not logged.
Further, also ensured that if an attribute is set to None it does not try to convert the None value to Fahrenheit as that will cause an error.
* Cleaned up and added few comments
Cleaned up some lines based on flake8 and pylint.
Added some comment lines on the items added.
* Changed to async and using async_added_to_hass
Changed sensor to use async.
Registering state tracking for sensors and initial setup is now done upon the home assistant start event.
* Updated test and small fix
Updated test to handle unavailable state of sensor and return of None for attributes when data is unavailable.
Ensured that atributes are set to None when state is unavailable due to incorrect data.
* Fixed some flake8 issues in test
Fixed some flake8 issues in test_moldindicator.py.
* Updates based on review
Updates based on review from MartinHjelmare
* Added sensor entity_id to logger errors
Added sensor entity_id to logger error messages
Update test to use constant STATE_UNKNOWN instead of fixed string.
* Fix rangefilter
RangeFilter would break for lower or upper bounds of 0, evaluating to False and thus not being handled correctly as bounds
* Add test for zero bounds
* Refactored units and icons for the Dyson sensors
* Adapted unit tests to the new device names and unit of measurements
* Use None as empty unit of measurement
* Unrelated overall improvements following code review
* Adapted tests to new constructors as per previous commit
* Make sure the sensors have their `hass` attribute set in the test environment
* create binary sensor even if initial update fails
* fixed broken test assertion
* fixed broken test assertion
* avoid fetching resource twice - manually in the setup_platform and then through add_devices
* raising PlatformNotReady instead of creating the sensor if the initial rest call fails; throttling the update to avoid fetching the same resource again immediately after setting up sensor
* rolled back throttling of the rest update call; can still avoid updating the binary sensor's rest resoure twice; fixed tests
* typo
* 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