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

Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration #12883

Merged

Conversation

syssi
Copy link
Member

@syssi syssi commented Mar 3, 2018

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

Example entry for configuration.yaml (if applicable):

light:
  - platform: xiaomi_miio
    name: Xiaomi Philips EyeCare Smart Lamp 2
    host: 192.168.130.69
    token: e8b19da37825a3056e84c522f05efce0
    model: philips.light.sread1

self._light.delay_off, round(time_period.total_seconds()/60))


@asyncio.coroutine

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)

hass.data[DATA_KEY][host] = device
async_add_devices([device], update_before_add=True)

async_add_devices(devices, update_before_add=True)

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)

@syssi syssi changed the title Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration WIP: Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Mar 3, 2018
@syssi syssi changed the title WIP: Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Mar 4, 2018
@syssi syssi changed the title Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration [WIP] Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Mar 4, 2018
@syssi syssi changed the title [WIP] Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Mar 4, 2018
@syssi syssi changed the title Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration [WIP] Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Mar 4, 2018
@syssi syssi changed the title [WIP] Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Xiaomi MiIO light: Philips Eyecare Smart Lamp 2 integration Mar 4, 2018
hass.data[DATA_KEY][host] = device

device = XiaomiPhilipsEyecareLampAmbientLight(
name + ' Ambient Light', light, model)
Copy link
Member

Choose a reason for hiding this comment

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

Use '{} Ambient Light'.format(name)

devices.append(device)
hass.data[DATA_KEY][host] = device

device = XiaomiPhilipsEyecareLampAmbientLight(
Copy link
Member

Choose a reason for hiding this comment

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

Please don't reuse the same local variable name within the same scope. That's confusing.

"""Return the supported features."""
return SUPPORT_FLAGS_SREAD1_EYECARE_LIGHT

@asyncio.coroutine
Copy link
Member

Choose a reason for hiding this comment

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

We've migrated to async/await syntax. Please drop this decorator and prefix async methods with async like async def async_update. Replace any yield from with await.

"""Fetch state from the device."""
from miio import DeviceException
try:
state = yield from self.hass.async_add_job(self._light.status)
Copy link
Member

Choose a reason for hiding this comment

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

If you're going to call a sync method, you might as well just make the whole update method not async


async def async_set_delayed_turn_off(self, time_period: timedelta):
"""Set delayed turn off."""
if self._additional_supported_features & SUPPORT_SET_DELAYED_TURN_OFF == 0:

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

self._light.delay_off, time_period.total_seconds())
async def async_set_delayed_turn_off(self, time_period: timedelta):
"""Set delayed turn off."""
if self._additional_supported_features & SUPPORT_SET_DELAYED_TURN_OFF == 0:

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

syssi added 3 commits March 9, 2018 09:50
Unnecessary parens after 'return' keyword fixed.
@@ -210,14 +253,13 @@ def brightness(self):
@property
def supported_features(self):
"""Return the supported features."""
return SUPPORT_BRIGHTNESS
return 0
Copy link
Member

Choose a reason for hiding this comment

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

This should implement at least SUPPORT_BRIGHTNESS since you return the brightness in the property defined above this one?

@property
def supported_features(self):
"""Return the supported features."""
return SUPPORT_BRIGHTNESS
Copy link
Member

Choose a reason for hiding this comment

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

I see you implementing color temp in the constructor. Shouldn't that be included in the supported features?

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved the implementation to the correct class (bulb) now.

# pylint: disable=no-self-use
async def async_reminder_on(self):
"""Enable the eye fatigue notification."""
return
Copy link
Member

Choose a reason for hiding this comment

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

raise NotImplementedError

Copy link
Member Author

Choose a reason for hiding this comment

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

Is raising NotImplementedError correct here? Some devices (classes) doesn't support the feature / service. In this case the service call should be ignored. All xiaomi_miio lights uses the same DATA_KEY. If somebody calls light.xiaomi_miio_reminder_on (without an entity_id parameter) all entities will be addressed and the method needs to be accessible.

Copy link
Member

Choose a reason for hiding this comment

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

But why wouldn't the service call filter them out?

for device in devices:
    if not hasattr(device, 'async_reminder_on'):
        continue
    await device.async_reminder_on()

Copy link
Member Author

Choose a reason for hiding this comment

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

This is cool. Thanks!


async def async_reminder_on(self):
"""Enable the eye fatigue notification."""
if self._additional_supported_features & SUPPORT_REMINDER == 0:
Copy link
Member

Choose a reason for hiding this comment

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

Why this? You hardcode the additional features in the constructor

@balloob
Copy link
Member

balloob commented Mar 16, 2018

Support for Xiaomi Philips Zhirui Smart LED Bulb E14 Candle Lamp added.

Please stop adding types to this PR, it's already getting WAAY to big. try to limit PRs to 1 thing.


class XiaomiPhilipsEyecareLamp(XiaomiPhilipsGenericLight, Light):
except DeviceException as ex:
self._state = None
Copy link
Member

Choose a reason for hiding this comment

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

Instead of just setting state to None, the available property should return False

if model is None:
try:
miio_device = Device(host, token)
device_info = miio_device.info()
model = device_info.model
unique_id = "{}-{}".format(model, device_info.mac_address)
Copy link
Member

Choose a reason for hiding this comment

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

why include model and not just mac address ? Mac address should be unique per device.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see the primary/secondary device things now.

@balloob
Copy link
Member

balloob commented Mar 16, 2018

This is ok to merge once the available property is correctly set to False when the device cannot update.

"""Representation of a Xiaomi Philips Ceiling Lamp."""

def __init__(self, name, light, model, unique_id):
"""Initialize the light device."""
XiaomiPhilipsBulb.__init__(self, name, light, model, unique_id)
Copy link
Member

@rytilahti rytilahti Mar 16, 2018

Choose a reason for hiding this comment

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

The init calls should probably be done on super() (as that will keep it working even if the name of the super class changes).

@rytilahti
Copy link
Member

Great, thanks 👍

@rytilahti rytilahti merged commit fe70125 into home-assistant:dev Mar 16, 2018
@balloob balloob mentioned this pull request Mar 30, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
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