Skip to content

Mqtt cover modifications#7841

Merged
balloob merged 7 commits into
home-assistant:devfrom
cribbstechnologies:mqtt-cover-bugfix
Jun 5, 2017
Merged

Mqtt cover modifications#7841
balloob merged 7 commits into
home-assistant:devfrom
cribbstechnologies:mqtt-cover-bugfix

Conversation

@cribbstechnologies
Copy link
Copy Markdown
Contributor

@cribbstechnologies cribbstechnologies commented May 30, 2017

Description:

Making command topic optional so a tilt-only cover doesn't show up/down controls
Adding ability to set up/down position including ability to template the value

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

**also has modifications for polymer project - PR not ready yet

Example entry for configuration.yaml (if applicable):

cover:
  - platform: mqtt,
    name: test,
    state_topic: 'state-topic',
    command_topic: 'command-topic',
    set_position_topic: 'position-topic',
    set_position_template: '{{100-62}}',
    payload_open: 'OPEN',
    payload_close: 'CLOSE',
    payload_stop: 'STOP'

Checklist:

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

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

removing command_topic being required
@mention-bot
Copy link
Copy Markdown

@cribbstechnologies, thanks for your PR! By analyzing the history of the files in this pull request, we identified @pvizeli, @turbokongen and @balloob to be potential reviewers.

Comment thread tests/components/cover/test_mqtt.py Outdated
}
}))

state_attributes_dict = self.hass.states.get(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

local variable 'state_attributes_dict' is assigned to but never used

Comment thread tests/components/cover/test_mqtt.py Outdated
}
}))

state_attributes_dict = self.hass.states.get(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

local variable 'state_attributes_dict' is assigned to but never used

self.mock_publish.mock_calls[-2][1])


def test_no_command_topic(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

too many blank lines (2)

Comment thread tests/components/cover/test_mqtt.py Outdated
current_cover_position = self.hass.states.get(
'cover.test').attributes['current_position']
self.assertEqual(22, current_cover_position)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line contains whitespace

@bruhautomation
Copy link
Copy Markdown

bruhautomation commented May 31, 2017

Hey @balloob. Sorry for the direct tag. Anyway this can make it into 0.46? Would be clutch to have it out in the next release cycle. Me and @cribbstechnologies worked through my typos and I'm good to share my project soon.

@WoodsterDK
Copy link
Copy Markdown

Will it be possible to set the position with a customized json payload, e.g. like:

set_position_template: '{"covers": [1,2],"position" : value.position}'
where "value.position" gets substituted with the target position and then the complete json object is sent by mqtt?

Copy link
Copy Markdown
Contributor

@emlove emlove left a comment

Choose a reason for hiding this comment

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

I really like the method of passing the service call through a template. It gives great flexibility to handle scaling or whatever else the endpoint might need.

Comment thread homeassistant/components/cover/mqtt.py Outdated
self._position_topic = position_topic
self._set_position_template = set_position_template
if set_position_template is not None:
self._set_position_template.hass = hass
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.

Can you put this logic in async_setup_platform so we don't need to pass hass in? Let's make it look the same as value_template.

Comment thread homeassistant/components/cover/mqtt.py Outdated
if self._position_topic is not None:
supported_features |= SUPPORT_SET_POSITION

if self.current_cover_position is not None:
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 this should now be removed since we're using self._position_topic to define SUPPORT_SET_POSITION. It probably shouldn't have been set before.

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 you mean remove the block starting at line 262?

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.

Yes, that's right.

Comment thread homeassistant/components/cover/mqtt.py Outdated
position = kwargs[ATTR_POSITION]
if self._set_position_template is not None:
try:
position = self._set_position_template.async_render()
Copy link
Copy Markdown
Contributor

@emlove emlove May 31, 2017

Choose a reason for hiding this comment

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

Change this to async_render(**kwargs). This will make the requested position from the service available to the template. Should also be noted in the docs.

Copy link
Copy Markdown
Contributor

@emlove emlove left a comment

Choose a reason for hiding this comment

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

LGTM, except the polymer submodule update needs to be removed.

This reverts commit 9cfc5ed.
@cribbstechnologies
Copy link
Copy Markdown
Contributor Author

cribbstechnologies commented May 31, 2017 via email

@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 5, 2017

@armills if you approve, you can merge it too in the future 👍

Sorry, didn't make 0.46 as I am not really paying attention to notifications anymore (too many).

@balloob balloob merged commit 774f584 into home-assistant:dev Jun 5, 2017
@bruhautomation
Copy link
Copy Markdown

No worries! I'm trying out a new 12v stepper right now since I have the extra time. Should be a good video once I have everything ready. Thanks much for everyone's work getting the MQTT tilt component integrated!

@WoodsterDK
Copy link
Copy Markdown

Untill it gets into the released version, will it then be enough to copy the modified cover/mqtt.py file into the custom component library?

balloob pushed a commit that referenced this pull request Jun 9, 2017
* adding set position ability
removing command_topic being required

* flaking

* flaking test

* updating docs

* requested updates

* Revert "updating docs"

This reverts commit 9cfc5ed.

* forgot to update constructor calls in tests
@balloob balloob added this to the 0.46.1 milestone Jun 9, 2017
@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 9, 2017

Will cherry-pick it for 0.46.1

@balloob balloob mentioned this pull request Jun 9, 2017
@balloob balloob mentioned this pull request Jun 16, 2017
@WoodsterDK
Copy link
Copy Markdown

Can anyone guide me in the right direction setting this mqtt cover up.
My cover supports different positions between 0-100 percent - the topic is given, but the payload is a json object, where the parameter is part of, e.g.:

{"covers": [1,2],"position" : 50}

How is this done, using the latest template feature?

@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
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.

9 participants