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

Add Google pubsub component #20049

Merged
merged 10 commits into from Feb 10, 2019

Conversation

Projects
None yet
7 participants
@timvancann
Copy link
Contributor

timvancann commented Jan 13, 2019

Description:

This adds the Google Pub/Sub component to directly post event changes from Home Assistant to Pub/Sub. This allows for many streaming applications, from cloud dashboarding to cloud data science.

Related issue (if applicable): fixes #

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

Example entry for configuration.yaml (if applicable):

See new documentation

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

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 or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

timvancann added some commits Jan 13, 2019

@timvancann timvancann force-pushed the timvancann:google_pubsub branch from b36a9cc to c6dd89a Jan 13, 2019

@homeassistant

This comment has been minimized.

Copy link

homeassistant commented Jan 13, 2019

Hi @timvancann,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@timvancann timvancann referenced this pull request Jan 13, 2019

Merged

Google pubsub #8153

2 of 2 tasks complete

@timvancann timvancann force-pushed the timvancann:google_pubsub branch from 2495b7d to 31a58ca Jan 14, 2019

@timvancann timvancann force-pushed the timvancann:google_pubsub branch from ec149de to e968410 Feb 1, 2019

@amelchio amelchio self-assigned this Feb 8, 2019

@amelchio
Copy link
Member

amelchio left a comment

This looks really good 👍. Just a couple of comments ...

_LOGGER.error("Path to credentials file cannot be found")
return False

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = service_principal_path

This comment has been minimized.

@amelchio

amelchio Feb 8, 2019

Member

Is there some way to pass this without modifying the global environment?

This comment has been minimized.

@timvancann

timvancann Feb 10, 2019

Author Contributor

Did some digging, and yes, there is 😄. Fixed it

"""Implement encoding logic."""
if isinstance(o, datetime.datetime):
return o.isoformat()
return super(DateTimeJSONEncoder, self).default(o)

This comment has been minimized.

@amelchio

amelchio Feb 8, 2019

Member

I think super() is enough with Python 3.

This comment has been minimized.

@timvancann

timvancann Feb 10, 2019

Author Contributor

Absolutely right.

@amelchio amelchio removed their assignment Feb 8, 2019

@home-assistant home-assistant deleted a comment from homeassistant Feb 10, 2019

"""Activate Google Pub/Sub component."""
from google.cloud import pubsub_v1 # pylint: disable=E0611

config = yaml_config.get(DOMAIN, {})

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Feb 10, 2019

Member

When would the DOMAIN key be missing in the config dict? Why do we need to use dict.get?

This comment has been minimized.

@timvancann

timvancann Feb 10, 2019

Author Contributor

It shouldn't be missing. Changed it to dict[]

Show resolved Hide resolved homeassistant/components/google_pubsub/__init__.py
class DateTimeJSONEncoder(json.JSONEncoder):
"""Encode python objects.
Additonaly add encoding for datetime objects as isoformat.

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Feb 10, 2019

Member

Additionally

This comment has been minimized.

@timvancann

timvancann Feb 10, 2019

Author Contributor

👍

Code review comment
- Remove pylint ignores
- Don't modify global environment

@timvancann timvancann force-pushed the timvancann:google_pubsub branch from cea6658 to c08a13a Feb 10, 2019

@amelchio amelchio merged commit d049b52 into home-assistant:dev Feb 10, 2019

5 checks passed

Hound No violations found. Woof!
WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.04%) to 93.319%
Details

@wafflebot wafflebot bot removed the in progress label Feb 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment