Skip to content

Add Google pubsub component#20049

Merged
amelchio merged 10 commits into
home-assistant:devfrom
timvancann:google_pubsub
Feb 10, 2019
Merged

Add Google pubsub component#20049
amelchio merged 10 commits into
home-assistant:devfrom
timvancann:google_pubsub

Conversation

@timvancann
Copy link
Copy Markdown
Contributor

@timvancann 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.

@homeassistant
Copy link
Copy Markdown
Contributor

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!

Comment thread homeassistant/components/google_pubsub/__init__.py Outdated
Comment thread homeassistant/components/google_pubsub/__init__.py
Comment thread homeassistant/components/google_pubsub/__init__.py
Comment thread homeassistant/components/google_pubsub/__init__.py
Comment thread homeassistant/components/google_pubsub/__init__.py
Comment thread homeassistant/components/google_pubsub/__init__.py Outdated
Comment thread homeassistant/components/google_pubsub/__init__.py Outdated
Comment thread homeassistant/components/google_pubsub/__init__.py
@amelchio amelchio self-assigned this Feb 8, 2019
Copy link
Copy Markdown
Contributor

@amelchio amelchio left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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.

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think super() is enough with Python 3.

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.

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, {})
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.

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

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.

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

Comment thread homeassistant/components/google_pubsub/__init__.py
class DateTimeJSONEncoder(json.JSONEncoder):
"""Encode python objects.

Additonaly add encoding for datetime objects as isoformat.
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.

Additionally

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.

👍

- Remove pylint ignores
- Don't modify global environment
@amelchio amelchio merged commit d049b52 into home-assistant:dev Feb 10, 2019
@ghost ghost removed the in progress label Feb 10, 2019
@balloob balloob mentioned this pull request Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants