Skip to content

New sensor domain expiry#14067

Merged
pvizeli merged 5 commits intohome-assistant:devfrom
masarliev:domain_expiry
Apr 25, 2018
Merged

New sensor domain expiry#14067
pvizeli merged 5 commits intohome-assistant:devfrom
masarliev:domain_expiry

Conversation

@masarliev
Copy link
Copy Markdown
Contributor

@masarliev masarliev commented Apr 24, 2018

Description:

Domain expiry sensor.

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5242

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: domain_expiry
    domain: google.com
    name: google

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

Copy link
Copy Markdown
Member

@OttoWinter OttoWinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍 I'm already looking forward to this integration.

add_devices([DomainExpiry(sensor_name, server_name)],
True)

hass.bus.listen_once(EVENT_HOMEASSISTANT_START, run_setup)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to wait until Home Assistant start with this platform. Only cert_expiry needs it so that the frontend can show it's ask certificate.

Because the DNS server is running independent of Home Assistant, here we don't need to wait.

"""Fetch the domain information."""
import whois
domain = whois.whois(self.server_name)
expiry = domain.expiration_date - datetime.today()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this handle non-UTC timezones? How does whois.whois return the expiration date? Your code is probably ok, just checking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expiration date from whois is in UTC


SCAN_INTERVAL = timedelta(hours=24)

TIMEOUT = 10.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused?


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up domain expiry sensor."""
def run_setup(event):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you delaying the setup?

expiry = domain.expiration_date - datetime.today()
self._state = expiry.days
else:
_LOGGER.error("Cannot get expiry date for %s", self.server_name)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set self._state = None ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change it because expiration date will always be datetime. This check is for some domains that don't share this information and error will be triggered only for them

@frenck
Copy link
Copy Markdown
Member

frenck commented Apr 24, 2018

IMHO opinion, the host configuration variable should be renamed to domain to better match the actual thing we are monitoring here. Secondly, the host variable is used to define the host to connect to in many many components and actually, we are not connecting to it in this case.

@fanaticDavid
Copy link
Copy Markdown
Contributor

fanaticDavid commented Apr 24, 2018

Valid point, but the Certificate Expiry sensor (which probably served as a point of reference here) uses host instead of domain as well.

@OttoWinter
Copy link
Copy Markdown
Member

OttoWinter commented Apr 24, 2018

@fanaticDavid True, but that doesn't mean we should repeat past mistakes. In the end, it's not going to be that big of a deal with either choice, users will have to go to the home-assistant.io component page anyway for setting up the integration.

I personally value the direct user experience through descriptive configuration keys more than consistency. (That doesn't mean consistency is not important, it is, but that it's not that high of a priority in this case)

@fanaticDavid
Copy link
Copy Markdown
Contributor

fanaticDavid commented Apr 24, 2018

@OttoWinter I agree, we should not repeat past mistakes. I would change host to domain for this new integration as @frenck suggested. Personally, I'm OCD enough to be okay with a breaking change for the Certificate Expiry sensor in the name of consistency, but that's not my call to make 😜

@OttoWinter
Copy link
Copy Markdown
Member

I mean one thing speaking against changing it for cert_expiry is that for that sensor it is actually a host. For example, you can use an IP address with the cert_expiry platform.

The difference is that the cert_expiry platform actually does set up a connection to the specified host (+ port!) and checks the server for a valid certificate. The domain_expiry sensor on the other hand never connects to the actual target domain and just uses DNS queries, so it does not connect to a "host".

@fanaticDavid
Copy link
Copy Markdown
Contributor

fanaticDavid commented Apr 24, 2018

I stand corrected! Now, back on topic... 😛

@frenck
Copy link
Copy Markdown
Member

frenck commented Apr 25, 2018

Thanks for the adjustment @masarliev! 👍

@pvizeli pvizeli merged commit f23f946 into home-assistant:dev Apr 25, 2018
@fabaff
Copy link
Copy Markdown
Member

fabaff commented May 10, 2018

This is pretty much a duplicate of the already available whois sensor.

@masarliev
Copy link
Copy Markdown
Contributor Author

Yes. It's same. As it seems I didn't know about whois sensor. Should we delete this sensor?

@balloob
Copy link
Copy Markdown
Member

balloob commented May 10, 2018

Yes. Opening a PR for that now.

@balloob
Copy link
Copy Markdown
Member

balloob commented May 10, 2018

#14381

@balloob balloob mentioned this pull request May 11, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants