Fix errors if rest source becomes unavailable #24986
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Fixes errors when rest URL becomes unavailable
Example:
Jul 06 10:39:32 home-assistant hass[346193]: 2019-07-06 10:39:32 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.brayden_tv_source fails
Jul 06 10:39:32 home-assistant hass[346193]: Traceback (most recent call last):
Jul 06 10:39:32 home-assistant hass[346193]: File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 220, in async_update_ha_state
Jul 06 10:39:32 home-assistant hass[346193]: await self.async_device_update()
Jul 06 10:39:32 home-assistant hass[346193]: File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 377, in async_device_update
Jul 06 10:39:32 home-assistant hass[346193]: await self.hass.async_add_executor_job(self.update)
Jul 06 10:39:32 home-assistant hass[346193]: File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
Jul 06 10:39:32 home-assistant hass[346193]: result = self.fn(*self.args, **self.kwargs)
Jul 06 10:39:32 home-assistant hass[346193]: File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/scrape/sensor.py", line 115, in update
Jul 06 10:39:32 home-assistant hass[346193]: raw_data = BeautifulSoup(self.rest.data, 'html.parser')
Jul 06 10:39:32 home-assistant hass[346193]: File "/srv/homeassistant/lib/python3.7/site-packages/bs4/init.py", line 245, in init
Jul 06 10:39:32 home-assistant hass[346193]: elif len(markup) <= 256 and (
Jul 06 10:39:32 home-assistant hass[346193]: TypeError: object of type 'NoneType' has no len()
Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest
.requirements_all.txt
by runningpython3 -m script.gen_requirements_all
..coveragerc
.If the code does not interact with devices: