Skip to content
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

Move myStrom light and switch to async #34079

Merged
merged 2 commits into from
Apr 23, 2020
Merged

Move myStrom light and switch to async #34079

merged 2 commits into from
Apr 23, 2020

Conversation

fabaff
Copy link
Member

@fabaff fabaff commented Apr 12, 2020

Proposed change

  • Move myStrom light and switch to async
  • Upgrade python-mystrom to 1.1.2
  • Update docs strings
  • Update log entries
  • Align various parts of the platforms

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml
switch:
  - platform: mystrom
    host: 192.168.0.50

light:
  - platform: mystrom
    host: 192.168.0.51
    mac: 5CxxxxxxxxxB0

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

return self._mac

@property
def device_info(self):
Copy link
Member

Choose a reason for hiding this comment

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

This is only used when using a config entry. So remove it until that's added.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed for now.

def device_info(self):
"""Return device specific attributes."""
return {
"identifiers": {(DOMAIN, self.unique_id)},
Copy link
Member

@balloob balloob Apr 12, 2020

Choose a reason for hiding this comment

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

When you add it back, change this one to "connections": {(CONNECTION_MAC, self._mac)},

return {
"identifiers": {(DOMAIN, self.unique_id)},
"name": self._name,
"manufacturer": DOMAIN,
Copy link
Member

Choose a reason for hiding this comment

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

Proper capitalize.

"identifiers": {(DOMAIN, self.unique_id)},
"name": self._name,
"manufacturer": DOMAIN,
"model": self.bulb_type,
Copy link
Member

Choose a reason for hiding this comment

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

This would be rgblamp. I doubt it's called like that on their site. Maybe RGB Lamp or even something completely else?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's not but that's what the API is returning. I will change that.

except MyStromConnectionError:
_LOGGER.error("No route to device: %s", host)
_LOGGER.error("No route to myStrom plug: %s", host)
raise PlatformNotReady()
Copy link
Member

Choose a reason for hiding this comment

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

This was missing from light.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it was.

raise PlatformNotReady()

add_entities([MyStromSwitch(name, host)])
async_add_entities([MyStromSwitch(plug, name, plug.mac)])
Copy link
Member

Choose a reason for hiding this comment

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

Why do we pass plug.mac to the class, if we also pass plug in?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I thought that it would be more clear what's happening. Switched to use plug.

Comment on lines 110 to 111
self.firmware = self.plug.firmware
self.consumption = self.plug.consumption
Copy link
Member

Choose a reason for hiding this comment

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

Why store this as instance variables instead of just returning it as self.plug.firmware when needed?

return self.mac

@property
def device_info(self):
Copy link
Member

Choose a reason for hiding this comment

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

Remove this and re-introduce when a config flow is added.

self.firmware = self.plug.firmware
self.consumption = self.plug.consumption
self.relay = self.plug.relay

self._available = True
except MyStromConnectionError:
self.data = {"power": 0, "relay": False}
Copy link
Member

Choose a reason for hiding this comment

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

self.data is not used ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

@balloob balloob merged commit 637ff56 into dev Apr 23, 2020
@balloob balloob deleted the mystrom-unique branch April 23, 2020 23:00
@lock lock bot locked and limited conversation to collaborators Apr 25, 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.

Mystrom integration is broken in 0.108
3 participants