Skip to content

Add MELCloud integration#30712

Merged
rytilahti merged 35 commits into
home-assistant:devfrom
vilppuvuorinen:integration-melcloud
Feb 10, 2020
Merged

Add MELCloud integration#30712
rytilahti merged 35 commits into
home-assistant:devfrom
vilppuvuorinen:integration-melcloud

Conversation

@vilppuvuorinen
Copy link
Copy Markdown
Contributor

@vilppuvuorinen vilppuvuorinen commented Jan 12, 2020

Description:

This stuff is not supported nor in any way affiliated with Mitsubishi Electric.

Provides climate and sensor platforms for Mitsubishi Electric heat pumps connected to MELCloud service. Multiple platforms on one go is not the best option, but it does not make sense to remove them and commit them later either. This thing started as a custom_component.

Email and access token are stored to the ConfigEntry. The token can be updated by adding the integration again with the same email address. The config flow is aborted and the update is performed on the background. This is a bit unorthodox, but at least I like it better than storing the plain-text password.

Additional information

Link to documentation pull request: home-assistant/home-assistant.io#11930

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.
  • I have followed the development checklist

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

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

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

@vilppuvuorinen
Copy link
Copy Markdown
Contributor Author

@frenck Do I need to provide docs PR before any review is done? I can do the docs PR, but I don't want to commit time to doing that without knowing if this is something that can/will be merged.

Copy link
Copy Markdown
Member

frenck commented Jan 13, 2020

Docs are required before being able to merge. I've added it to ensure we do not merge it accidentally without documentation.

@vilppuvuorinen vilppuvuorinen changed the title WIP: Add MELCloud integration Add MELCloud integration Jan 14, 2020
@rudizl
Copy link
Copy Markdown

rudizl commented Jan 25, 2020

Excellent work, fingers crossed!

@gdude2002
Copy link
Copy Markdown

I attempted to test this component on my own HA install, but it appears to assume that MELCloud is only used for HVAC/AC systems. When tested with my system (simply an air-to-water system), I noted that the component just presumed that I had an HVAC system. It also doesn't show any zones, and only the first sensor (the power one) reports anything.

image

Is this out of scope of this PR, or is this unintentional?

@vilppuvuorinen
Copy link
Copy Markdown
Contributor Author

I think the air-to-water systems are out of scope, but the lack of filtering is not. I also noticed I'm not filtering out empty model numbers for that device info like I though I did.

I have some read-only stuff for air-to-water systems here, but it has just temperatures for now. I would need help with that because I'm doing this with a blackbox or record/replay type approach (just in case) and therefore I don't have access to the source code of the original application. Help would be appreaciated. Right now it would be awesome to have captures of /Device/Get response body and bodies of individual parameter updates requests (SetAta) done at least 1 minute apart. That data is awful to anonymize. You can find me on home-assistant Discord.

@gdude2002
Copy link
Copy Markdown

While working with @vilppuvuorinen on Discord to get some testing data, I produced a Gist with some dumped data. To keep things together and to provide a resource for random internet wanderers, I'm linking it here.

Thanks for looking into this!

Comment thread homeassistant/components/melcloud/__init__.py
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/climate.py Outdated
speed = self._api.device.fan_speed
if speed is None:
return None
return speed.replace("-", " ")
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.

Maybe this replace belongs to the backend library?

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.

There's a supposedly dynamic amount of fan speeds available in these devices. The backend lib doing this speed-%d mapping for them and this is just to turn that "constant-y" string to "human readable" variant. What I'm trying to say is that I think the replace belongs here, but it just sucks.

Would it be better to use the FAN_* fan mode constants here instead of sequentially numbered speeds? I should be possible at least, but I don't know if it has any benefits.

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.

Sorry, I don't know about the details, but maybe using those constants will help when it comes to consistency (think: usage via voice controls)?


async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode."""
await self._api.device.set({"fan_speed": fan_mode.replace(" ", "-")})
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.

See above wrt. replace.

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.

FAN_* built-in mode mappings could work here too.

Comment thread homeassistant/components/melcloud/climate.py Outdated
Comment thread homeassistant/components/melcloud/config_flow.py Outdated
@MuppetOwl
Copy link
Copy Markdown

Swing modes (vertical vane adjusting) is missing Auto, Top, MiddleTop, Middle, MiddleBottom, Bottom and Swing
Also Heat/cool should maybe be renamed to Auto? Like it was in o0Zz version and is also what its called in Melcloud.

Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/climate.py Outdated
Comment thread homeassistant/components/melcloud/climate.py Outdated
Comment thread homeassistant/components/melcloud/climate.py Outdated
speed = self._api.device.fan_speed
if speed is None:
return None
return speed.replace("-", " ")
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.

Sorry, I don't know about the details, but maybe using those constants will help when it comes to consistency (think: usage via voice controls)?

Comment thread homeassistant/components/melcloud/climate.py Outdated
@vilppuvuorinen
Copy link
Copy Markdown
Contributor Author

@MuppetOwl I'll have to backtrack on my comments on the forum. HVAC_MODE_AUTO is described as "The device is set to a schedule, learned behavior, AI." and that's definitely not the case here. I'll stick with HVAC_MODE_HEAT_COOL.

Copy link
Copy Markdown
Member

@rytilahti rytilahti 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 fine to me, I left a couple of comments on very minor issues, maybe someone else can also take a quick look before getting this merged?

Comment thread homeassistant/components/melcloud/__init__.py
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/climate.py Outdated
Copy link
Copy Markdown
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Looks good to me, but considering the PRs merged by myself often get commented after the merge, I hope someone else will also take a quick look before we proceed with merging :-) (ping @MartinHjelmare ;-))

Comment thread homeassistant/components/melcloud/manifest.json Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/climate.py Outdated
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Don't we want to set up a way to refresh the token automatically?

Comment thread .coveragerc
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread tests/components/melcloud/test_config_flow.py Outdated
Comment thread tests/components/melcloud/test_config_flow.py Outdated
Comment thread tests/components/melcloud/test_config_flow.py Outdated
Comment thread tests/components/melcloud/test_config_flow.py Outdated
Comment thread tests/components/melcloud/test_config_flow.py Outdated
@vilppuvuorinen
Copy link
Copy Markdown
Contributor Author

@MartinHjelmare Regarding the token update. I don't think it's possible to setup automatic token update without storing the password. There's a OAuth provider attached to the service, but that's aimed at Alexa integration and such. The response from customer service was hostile enough so that's definitely off the table.

I was hoping I could avoid storing the password. Should I just bite the bullet and store the password and implement token refresh? The tokens seem to be extremely long lived and therefore it is also difficult to assess how the expiry logic would work.

Regarding imports: Should I use relative imports for importing things from the homeassistant/components/melcloud directory?

I'll see about the other comments later today.

@MartinHjelmare
Copy link
Copy Markdown
Member

Ok, let's keep the token handling like it is for now.

We have helpers for implementing an oauth flow in the config flow if you want to try that in the future. Maybe you've already read that?

https://developers.home-assistant.io/docs/en/config_entries_config_flow_handler.html#configuration-via-oauth2

Yes, intra-package imports should be relative.

* Provides a climate and sensor platforms. Multiple platforms on one go
is not the best option, but it does not make sense to remove them and
commit them later either.

* Email and access token are stored to the ConfigEntry. The token can be
updated by adding the integration again with the same email address. The
config flow is aborted and the update is performed on the background.
Vilppu Vuorinen added 11 commits February 9, 2020 20:38
Entry setup used half-baked naming from few experimentations back.
The naming conventiens were unified to match the platforms.

A redundant noneness check was also removed after evaluating the
possible return values from the backend lib.
* Use config_validation strings.

* Add CONF_EMAIL to config schema. The value is not strictly required
when configuring through configuration.yaml, but having it there makes
things more consistent.

* Use dict[key] to access required properties.

* Add DOMAIN in config check back to async_setup. This is required if an
integration is configured throught config_flow.
* any -> Any

* Better names for dict iterations

* Proper dict access with mandatory/known keys

* Remove unused 'name' argument

* Remove unnecessary platform info from unique_ids

* Remove redundant methods from climate platform

* Remove redundant default value from dict get

* Update ConfigFlow sub-classing

* Define sensors in a dict instead of a list
Comment thread homeassistant/components/melcloud/__init__.py Outdated
Comment thread homeassistant/components/melcloud/sensor.py Outdated
Comment thread homeassistant/components/melcloud/sensor.py Outdated
Comment thread tests/components/melcloud/test_config_flow.py Outdated
@vilppuvuorinen
Copy link
Copy Markdown
Contributor Author

That test failure does not make sense to me. As if pylint didn't see the usage at homeassistant/components/melcloud/config_flow.py:19.

Comment thread homeassistant/components/melcloud/config_flow.py Outdated
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Nice!

@vilppuvuorinen
Copy link
Copy Markdown
Contributor Author

Should I squash the commits now?

@MartinHjelmare
Copy link
Copy Markdown
Member

No, please don't do that. We'll squash when merging.

@codecov

This comment has been minimized.

Copy link
Copy Markdown
Member

@springstan springstan left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@rytilahti
Copy link
Copy Markdown
Member

Considering we have already three approvals, let's get this merged. Thanks @vilppuvuorinen! 🎉

@rytilahti rytilahti merged commit b78d156 into home-assistant:dev Feb 10, 2020
@lock lock Bot locked and limited conversation to collaborators Feb 12, 2020
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