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.set_percentage 0 会执行关闭然后立刻启动 #1212

Closed
Necroneco opened this issue Jul 19, 2023 · 4 comments
Closed

fan.set_percentage 0 会执行关闭然后立刻启动 #1212

Necroneco opened this issue Jul 19, 2023 · 4 comments
Labels
bug Something isn't working device: fan

Comments

@Necroneco
Copy link
Contributor

Necroneco commented Jul 19, 2023

Device model / 设备型号

dmaker.fan.p8 (很多同类风扇都有这个问题)

Component version / 插件版本

0.7.10

HA core version / HA版本

2023.7.2

Integrated mode / 集成方式

Automatic (自动模式)

The problem / 问题详情

image

在 HA 2023.4 新版的 Fan 界面上点击关闭,会执行关闭然后立刻启动

观察日志发现,似乎内部调用的是 fan.set_percentage(0)

FanEntity 的代码,它在 percentage == 0 的时候先执行了 async_turn_off 然后再调用了组件的 set_percentage

MiotFanEntityset_percentage 会走到 turn_on 的开头,判断 if not self.is_on: 就先打开电源...

class FanEntity(ToggleEntity):
    ...
    async def async_set_percentage(self, percentage: int) -> None:
        """Set the speed of the fan, as a percentage."""
        if percentage == 0:
            await self.async_turn_off()  # <-- 1: 关闭
        await self.hass.async_add_executor_job(self.set_percentage, percentage)  # <-- 2: percentage is 0
    ...

https://github.com/home-assistant/core/blob/3b501fd2d7495b0336a5e254dc0c508daec189a1/homeassistant/components/fan/__init__.py#L199C1-L203C80

class MiotFanEntity(MiotToggleEntity, FanEntity):
    ...
    def set_percentage(self, percentage: int):
        return self.turn_on(percentage=percentage)  # <-- 3: percentage is 0
    ...
    def turn_on(self, speed=None, percentage=None, preset_mode=None, **kwargs):
        ret = False
        if not self.is_on:
            ret = self.set_property(self._prop_power, True)  # <-- 4: 打开
        if self._prop_percentage:
            ...
        elif self._prop_speed:
            ...
        ...
    ...

https://github.com/al-one/hass-xiaomi-miot/blob/15a626678ef64624b557f83b88bdbf8d7880798d/custom_components/xiaomi_miot/fan.py#L143C1-L176C19

Entity attributes / 实体属性

preset_modes:
  - Straight Wind
  - Sleep
oscillating: true
percentage: 33
percentage_step: 33
preset_mode: Straight Wind
model: dmaker.fan.p8
lan_ip: 
mac_address: 
entity_class: MiotFanEntity
home_room: 
miot_type: urn:miot-spec-v2:device:fan:0000A005:dmaker-p8:2
fan.on: true
fan.fan_level: 1
fan.horizontal_swing: true
fan.mode: 0
fan.off_delay_time: 0
fan.alarm: false
fan.brightness: true
indicator_light.on: true
alarm: false
physical_controls_locked: false
state_updater: lan
sub_entities:
  - fan-2.horizontal_swing-3
  - fan-2.alarm-11
  - alarm-4.alarm-1
  - fan-2.off_delay_time-10
  - physical_controls_locked-3.physical_controls_locked-1
  - indicator_light-5
friendly_name: 米家落地扇 Fan
supported_features: 11

Home Assistant Logs / 系统日志

米家落地扇 Fan 已开启 由服务触发 fan.set_percentage
22:25:56 - 19分钟前 -
米家落地扇 Fan 已关闭 由服务触发 fan.set_percentage
22:25:56 - 20分钟前 -

@al-one al-one added bug Something isn't working device: fan labels Jul 21, 2023
@al-one
Copy link
Owner

al-one commented Jul 21, 2023

尝试master分支。

@Necroneco
Copy link
Contributor Author

感谢,可以使用。

顺便问一句,这样改会实际调用了两次 turn_off 吗?

@al-one
Copy link
Owner

al-one commented Jul 22, 2023

顺便问一句,这样改会实际调用了两次 turn_off 吗?

会调用两次,但是应该没什么影响,主要为了兼容旧版HA。

@Necroneco
Copy link
Contributor Author

嗯 好的~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working device: fan
Projects
None yet
Development

No branches or pull requests

2 participants