syssi / xiaomiplug

Xiaomi Mi Smart WiFi Socket integration for Home Assistant
Apache License 2.0
107 stars 26 forks source link

acpartner v3 switch not updating correctly #15

Closed mouth4war closed 5 years ago

mouth4war commented 5 years ago

So now turn_on and turn_off work but soon after using turn_on, the switch loses sync by going off. The actual relay is still on.

status update is not working properly.

debug log for turn_on, new state shows power off and load power shows the load so its clearly on:

[custom_components.switch.xiaomi_miio] Response received from plug: ['ok']
[custom_components.switch.xiaomi_miio] Got new state: <AirConditioningCompanionStatus power=off, load_power=2479, air_condition_model=00000000ffffffff00, model_format=0, device_type=0, air_condition_brand=0, air_condition_remote=4294967295, state_format=0, air_condition_configuration=0130FF00, led=True, target_temperature=255, swing_mode=SwingMode.On, fan_speed=FanSpeed.Auto, mode=OperationMode.Cool>
mouth4war commented 5 years ago

I think the library is reporting power=off. Maybe there are different attributes for power for AC mode and Plug mode.

syssi commented 5 years ago

I picked a special property called socket_power for the device state:

https://github.com/syssi/xiaomiplug/blob/develop/custom_components/switch/xiaomi_miio.py#L544

This property (socket_power) isn't exposed from AirConditioningCompanionStatus.repr() at the moment. Could you enable the debug output of the component and library by:

# configuration.yaml

logger:
  default: warn
  logs:
    custom_components.switch.xiaomi_miio: debug
    miio: debug

And provide some logs? I'm interested in the response of:

power_socket = self.send("get_device_prop", ["lumi.0", "plug_state"]) https://github.com/rytilahti/python-miio/blob/master/miio/airconditioningcompanion.py#L482

It should be "on" and "off".

syssi commented 5 years ago

https://github.com/rytilahti/python-miio/pull/447/files

mouth4war commented 5 years ago

OK with your updated code, I get this after turn_on

[custom_components.switch.xiaomi_miio] Got new state: <AirConditioningCompanionStatus power=off, power_socket=['on'], load_power=829, air_condition_model=00000000ffffffff00, model_format=0, device_type=0, air_condition_brand=0, air_condition_remote=4294967295, state_format=0, air_condition_configuration=01101900, led=True, target_temperature=25, swing_mode=SwingMode.On, fan_speed=FanSpeed.Medium, mode=OperationMode.Cool>

mouth4war commented 5 years ago

turn_off:

[custom_components.switch.xiaomi_miio] Got new state: <AirConditioningCompanionStatus power=off, power_socket=['off'], load_power=0, air_condition_model=00000000ffffffff00, model_format=0, device_type=0, air_condition_brand=0, air_condition_remote=4294967295, state_format=0, air_condition_configuration=01101900, led=True, target_temperature=25, swing_mode=SwingMode.On, fan_speed=FanSpeed.Medium, mode=OperationMode.Cool>

syssi commented 5 years ago

Perfect! This is a bug. Please update the custom component.