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

fan.xiaomi_miio_set_oscillation_angle accepts strings only #9

Closed
syssi opened this issue Jun 5, 2018 · 5 comments
Closed

fan.xiaomi_miio_set_oscillation_angle accepts strings only #9

syssi opened this issue Jun 5, 2018 · 5 comments

Comments

@syssi
Copy link
Owner

syssi commented Jun 5, 2018

fan.xiaomi_miio_set_oscillation_angle {"angle": 30} / {"angle": 60} / {"angle": 90} / {"angle": 120}

using numeric value seems to hang whole Hass.io :-/ passing string values works only for: "30", "60", "90", "120" for other values nothing happens and get this king of error: Invalid service data for fan.xiaomi_miio_set_oscillation_angle: value is not allowed for dictionary value @ data['angle']. Got '50'

#4 (comment)
@jacekpaszkowski

@syssi
Copy link
Owner Author

syssi commented Jun 5, 2018

That's weird because the config schema evaluates a list of integeres:

SERVICE_SCHEMA_OSCILLATION_ANGLE = AIRPURIFIER_SERVICE_SCHEMA.extend({
    vol.Required(ATTR_ANGLE):
        vol.All(vol.Coerce(int), vol.In([30, 60, 90, 120]))
})

And the method signature expects an integer, too:

    async def async_set_oscillation_angle(self, angle: int) -> None:

Could you test it again with integers and may be debug log enabled?

I asked for testing some other values: For this tests the schema above must be extended temporary. Could a add the value 45 f.e., restart HA and try to call the service:

        vol.All(vol.Coerce(int), vol.In([30, 45, 60, 90, 120]))
fan.xiaomi_miio_set_oscillation_angle {"angle": 45}

Thanks for your support!

@MimbaMonkeyHouse
Copy link

MimbaMonkeyHouse commented Jun 11, 2018

Using {"angle": 30} or {"angle": 120} works fine here!
Using some random values like {"angle": 10} does not work.
Here is the error log:

Log Details (ERROR)
Mon Jun 11 2018 12:15:48 GMT+0800 (WITA)

Invalid service data for fan.xiaomi_miio_set_oscillation_angle: value is not allowed for dictionary value @ data['angle']. Got 10

This is normal behaviour. Please note that messing with the oscillation angle is approximative in Mi Home app too. Sometimes setting 30 deg will result in an oscillation of 90 deg.

Similarly even on the official app, the left/right direction functions do not work during oscillation. I need to stop the oscillation before changing the direction, then star the oscillation again. This is something we could make better here than on the app by stopping the oscillation, then changing the direction before starting the oscillation again automatically... Let me know if you would rather I add a feature request on here!

@syssi
Copy link
Owner Author

syssi commented Jun 11, 2018

Could you extend the validation schema by "the" random value

SERVICE_SCHEMA_OSCILLATION_ANGLE = AIRPURIFIER_SERVICE_SCHEMA.extend({
    vol.Required(ATTR_ANGLE):
        vol.All(vol.Coerce(int), vol.In([10, 30, 60, 90, 120]))
})

and restart HA? This time the HA error "value is not allowed for dictionary value @ data['angle']." won't be triggered and the value ("10") will be passed to the device. I'm interested in the response of the device.

@Alex0302
Copy link

Nothing happened, only errors in the log.

ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall fan.xiaomi_miio_set_oscillation_angle: angle=10>
Traceback (most recent call last):
  File "/home/hass/.homeassistant/custom_components/fan/xiaomi_miio_fan.py", line 306, in _try_command
    partial(func, *args, **kwargs))
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/miio/fan.py", line 334, in set_angle
  File "/srv/homeassistant/lib/python3.6/site-packages/miio/device.py", line 270, in send
    if "error" in m.data.value:
miio.exceptions.DeviceError: {'code': -5001, 'message': 'invaild_arg'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py", line 1007, in _event_to_service_call
    await service_handler.func(service_call)
  File "/home/hass/.homeassistant/custom_components/fan/xiaomi_miio_fan.py", line 227, in async_service_handler
    await getattr(device, method['method'])(**params)
  File "/home/hass/.homeassistant/custom_components/fan/xiaomi_miio_fan.py", line 506, in async_set_oscillation_angle
    self._device.set_angle, angle)
  File "/home/hass/.homeassistant/custom_components/fan/xiaomi_miio_fan.py", line 312, in _try_command
    _LOGGER.error(mask_error, exc)
  File "/usr/lib/python3.6/logging/__init__.py", line 1335, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/lib/python3.6/logging/__init__.py", line 1442, in _log
    self.handle(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 1452, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 1514, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 863, in handle
    self.emit(record)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/system_log/__init__.py", line 131, in emit
    entry = self._create_entry(record, stack)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/system_log/__init__.py", line 114, in _create_entry
    'message': record.getMessage(),
  File "/usr/lib/python3.6/logging/__init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting

@syssi
Copy link
Owner Author

syssi commented Jun 12, 2018

Thanks for your support. It looks like this feature works fine.

@syssi syssi closed this as completed Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants