Skip to content

Add lovelace websocket get and set card#17600

Merged
balloob merged 5 commits intohome-assistant:devfrom
bramkragten:lovelace-get-set
Oct 22, 2018
Merged

Add lovelace websocket get and set card#17600
balloob merged 5 commits intohome-assistant:devfrom
bramkragten:lovelace-get-set

Conversation

@bramkragten
Copy link
Copy Markdown
Member

@bramkragten bramkragten commented Oct 18, 2018

Description:

Related issue (if applicable): fixes #

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

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

error = None
try:
result = await hass.async_add_executor_job(
set_card, hass.config.path(LOVELACE_CONFIG_FILE),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

trailing whitespace

# Do we want to return config on save?
return True

raise CardNotFoundError("Card with ID: {} was not found in {}.".format(card_id, fname))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (91 > 79 characters)

if card.get('id') == card_id:
return object_to_yaml(card)

raise CardNotFoundError("Card with ID: {} was not found in {}.".format(card_id, fname))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (91 > 79 characters)

@balloob
Copy link
Copy Markdown
Member

balloob commented Oct 19, 2018

Good start! Can you add a test for set card.

@bramkragten bramkragten changed the title [WIP] Add lovelace webservice get and set card Add lovelace webservice get and set card Oct 19, 2018
@bramkragten bramkragten changed the title Add lovelace webservice get and set card Add lovelace websocket get and set card Oct 19, 2018
Like !include will now give an error in the frontend.
config = load_yaml(fname)
for view in config.get('views', []):
for card in view.get('cards', []):
if card.get('id') == card_id:
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.

you can reverse this statement to save an indentation and make code easier to read:

if card.get('id') != card_id:
    continue

card_config = yaml_to_object(card_config)
card.update(card_config)
save_yaml(fname, config)
return True
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.

No reason to return anything if we raise otherwise.

@balloob balloob added this to the 0.81 milestone Oct 22, 2018
@balloob balloob merged commit 96105ef into home-assistant:dev Oct 22, 2018
@ghost ghost removed the in progress label Oct 22, 2018
@bramkragten bramkragten deleted the lovelace-get-set branch October 22, 2018 21:21
balloob pushed a commit that referenced this pull request Oct 23, 2018
* Add ws get, set card

* lint+fix test

* Add test for set

* Added more tests, catch unsupported yaml constructors

Like !include will now give an error in the frontend.

* lint
@balloob balloob mentioned this pull request Oct 26, 2018
iantrich pushed a commit to iantrich/home-assistant that referenced this pull request Oct 27, 2018
* Add ws get, set card

* lint+fix test

* Add test for set

* Added more tests, catch unsupported yaml constructors

Like !include will now give an error in the frontend.

* lint
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
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.

5 participants