Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cert_expiry fails to load on 0.99.0b0 #26619

Closed
luca-angemi opened this issue Sep 13, 2019 · 5 comments · Fixed by #26638

Comments

@luca-angemi
Copy link
Contributor

commented Sep 13, 2019

Home Assistant release with the issue:
0.99.0b0

Last working Home Assistant release (if known):
0.98.5

Operating environment (Hass.io/Docker/Windows/etc.):
Hassbian

Component/platform:
cert_expiry

Description of problem:
cert_expiry doesn't work neither with yaml nor with config flow.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

sensor:
  platform: cert_expiry
  host: myhadomain.duckdns.org
  name: Certificate

Traceback (if applicable):
nothing appears in the logs

Additional information:
when using config flow:

image

@luca-angemi luca-angemi changed the title cert_expiry fails to load on 0.99b cert_expiry fails to load on 0.99.0b0 Sep 13, 2019
@probot-home-assistant

This comment has been minimized.

Copy link

commented Sep 13, 2019

Hey there @Cereal2nd, mind taking a look at this issue as its been labeled with a integration (cert_expiry) you are listed as a codeowner for? Thanks!

@Cereal2nd

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2019

there should be a t least something like this in the logs:

2019-09-13 16:22:20 INFO (MainThread) [homeassistant.setup] Setting up cert_expiry 2019-09-13 16:22:20 INFO (MainThread) [homeassistant.setup] Setup of domain cert_expiry took 0.0 seconds.
Looking at the screenshot this is a connection timeout, so this means that the socket.create_connection is timing out (more then 10 seconds) ...

@frenck frenck added this to the 0.99 milestone Sep 13, 2019
@dshokouhi

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2019

@Cereal2nd I am seeing the issue you are describing in the dev branch but i do not get an error as listed in bug. My issue is that the sensor does not get created after it says its successful.

image

2019-09-13 14:48:26 INFO (MainThread) [homeassistant.setup] Setting up cert_expiry
2019-09-13 14:48:26 INFO (MainThread) [homeassistant.setup] Setup of domain cert_expiry took 0.0 seconds.

the sensor only gets created after a HA reboot.

edit: when i attempt to import the configuration from configuration.yaml it works as expected, config entry created and sensor is there when it starts up. Seems to happen from user initiated flow only.

@MartinHjelmare

This comment has been minimized.

Copy link
Member

commented Sep 14, 2019

Looks like the problem is the callback that is listening for home assistant start to forward the entry setup to the sensor platform. On user entry creation home assistant will already have started so the platform won't get set up.

async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Load the saved entities."""
@callback
def async_start(_):
"""Load the entry after the start event."""
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, async_start)
return True

We should instead create the event listener in async_added_to_hass in the sensor entity, to run the first entity update when home assistant starts.

@MartinHjelmare

This comment has been minimized.

Copy link
Member

commented Sep 14, 2019

Found another problem with the certificate checking in the config flow. We need to schedule that call on the executor thread pool, since it does blocking I/O.

def _test_connection(self, user_input=None):
"""Test connection to the server and try to get the certtificate."""
try:
get_cert(user_input[CONF_HOST], user_input.get(CONF_PORT, DEFAULT_PORT))
return True
except socket.gaierror:
self._errors[CONF_HOST] = "resolve_failed"
except socket.timeout:
self._errors[CONF_HOST] = "connection_timeout"
except OSError:
self._errors[CONF_HOST] = "certificate_fetch_failed"
return False

Cereal2nd added a commit to Cereal2nd/home-assistant that referenced this issue Sep 14, 2019
@Cereal2nd Cereal2nd referenced this issue Sep 14, 2019
4 of 4 tasks complete
balloob added a commit that referenced this issue Sep 17, 2019
* Fix typo in translations

* Work on bug #26619

* readd the homeassistant.start event

* Remove the callback

* Added the executor_job for _test_connection

* Update test_config_flow.py
bramkragten added a commit that referenced this issue Sep 18, 2019
* Fix typo in translations

* Work on bug #26619

* readd the homeassistant.start event

* Remove the callback

* Added the executor_job for _test_connection

* Update test_config_flow.py
ochlocracy added a commit to ochlocracy/home-assistant that referenced this issue Sep 30, 2019
* Fix typo in translations

* Work on bug home-assistant#26619

* readd the homeassistant.start event

* Remove the callback

* Added the executor_job for _test_connection

* Update test_config_flow.py
ochlocracy added a commit to ochlocracy/home-assistant that referenced this issue Sep 30, 2019
* Fix typo in translations

* Work on bug home-assistant#26619

* readd the homeassistant.start event

* Remove the callback

* Added the executor_job for _test_connection

* Update test_config_flow.py
ochlocracy added a commit to ochlocracy/home-assistant that referenced this issue Oct 1, 2019
* Fix typo in translations

* Work on bug home-assistant#26619

* readd the homeassistant.start event

* Remove the callback

* Added the executor_job for _test_connection

* Update test_config_flow.py
ochlocracy added a commit to ochlocracy/home-assistant that referenced this issue Oct 1, 2019
* Fix typo in translations

* Work on bug home-assistant#26619

* readd the homeassistant.start event

* Remove the callback

* Added the executor_job for _test_connection

* Update test_config_flow.py
ochlocracy added a commit to ochlocracy/home-assistant that referenced this issue Oct 1, 2019
* Fix typo in translations

* Work on bug home-assistant#26619

* readd the homeassistant.start event

* Remove the callback

* Added the executor_job for _test_connection

* Update test_config_flow.py
ochlocracy added a commit to ochlocracy/home-assistant that referenced this issue Oct 1, 2019
* Fix typo in translations

* Work on bug home-assistant#26619

* readd the homeassistant.start event

* Remove the callback

* Added the executor_job for _test_connection

* Update test_config_flow.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.