Skip to content

Commit

Permalink
Merge branch 'release/2023.12.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Dec 20, 2023
2 parents 1e34612 + 1798a5a commit 48afb55
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 15 deletions.
29 changes: 26 additions & 3 deletions custom_components/xiaomi_miio_fan/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@
}


# backported from current master
def _filter_request_fields(req):
"""Return only the parts that belong to the request.."""
return {k: v for k, v in req.items() if k in ["did", "siid", "piid"]}

# pylint: disable=unused-argument
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the miio fan device from config."""
Expand Down Expand Up @@ -632,7 +637,7 @@ async def _try_command(self, mask_error, func, *args, **kwargs):
self._available = False
return False

async def async_turn_on(self, speed: str = None, **kwargs) -> None:
async def async_turn_on(self, speed: str = None, mode: str = None, **kwargs) -> None:
"""Turn the device on."""
result = await self._try_command(
"Turning the miio device on failed.", self._device.on
Expand Down Expand Up @@ -2256,6 +2261,7 @@ async def async_set_natural_mode_off(self):
class OperationModeFanP39(Enum):
Normal = 0
Nature = 1
Sleep = 2


class FanStatusP39(DeviceStatus):
Expand Down Expand Up @@ -2306,7 +2312,7 @@ class FanP39(MiotDevice):
"oscillate": {"siid": 2, "piid": 5},
"angle": {"siid": 2, "piid": 6},
"delay_off_countdown": {"siid": 2, "piid": 8},
"motor_control": {"siid": 2, "piid": 10},
"motor_control": {"siid": 2, "piid": 10, "access": ["write"]},
"speed": {"siid": 2, "piid": 11},
"child_lock": {"siid": 3, "piid": 1},
}
Expand All @@ -2318,10 +2324,27 @@ def __init__(
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
model: str = MODEL_FAN_P33,
model: str = MODEL_FAN_P39,
) -> None:
super().__init__(ip, token, start_id, debug, lazy_discover, model=model)

# backported and adapted from current master
def get_properties_for_mapping(self, *, max_properties=15) -> list:
"""Retrieve raw properties based on mapping."""
mapping = self._get_mapping()

# We send property key in "did" because it's sent back via response and we can identify the property.
properties = [
{"did": k, **_filter_request_fields(v)}
for k, v in mapping.items()
if "aiid" not in v
and ("access" not in v or "read" in v["access"])
]

return self.get_properties(
properties, property_getter="get_properties", max_properties=max_properties
)

def status(self):
"""Retrieve properties."""
return FanStatusP39(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_miio_fan/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/syssi/xiaomi_fan/issues",
"requirements": [
"construct==2.10.56",
"construct==2.10.68",
"python-miio>=0.5.12"
],
"version": "2023.7.0.0"
"version": "2023.12.0.0"
}
68 changes: 58 additions & 10 deletions custom_components/xiaomi_miio_fan/services.yaml
Original file line number Diff line number Diff line change
@@ -1,71 +1,119 @@
fan_set_buzzer_on:
name: Set buzzer on
description: Turn the buzzer on.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan

fan_set_buzzer_off:
name: Set buzzer off
description: Turn the buzzer off.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan

fan_set_child_lock_on:
name: Set child lock on
description: Turn the child lock on.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan

fan_set_child_lock_off:
name: Set child lock off
description: Turn the child lock off.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan

fan_set_led_brightness:
description: Set the led brightness.
name: Set LED brightness
description: Set the LED brightness.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan
brightness:
name: Brightness
description: Brightness (0 = Bright, 1 = Dim, 2 = Off)
example: 1

fan_set_natural_mode_on:
name: Set natural mode on
description: Turn the natural mode on.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan

fan_set_natural_mode_off:
name: Set natural mode off
description: Turn the natural mode off.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan

fan_set_oscillation_angle:
name: Set oscillation angle
description: Set the oscillation angle.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan
angle:
name: Angle
description: Supported values are 30, 60, 90, 120, 140 or 150 degrees.
example: 30

fan_set_delay_off:
name: Set delay off
description: Set the scheduled turn off time.
fields:
entity_id:
name: Entity ID
description: Name of the Xiaomi Mi Smart Fan entity.
example: "fan.xiaomi_smart_fan"
selector:
entity:
integration: xiaomi_miio_fan
domain: fan
delay_off_countdown:
name: Delay off countdown
description: Time in minutes. Valid values are 0, 60, 120, 180, 240, 300, 240, 300, 360, 420, 480 minutes.
example: 60
106 changes: 106 additions & 0 deletions custom_components/xiaomi_miio_fan/strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"services": {
"fan_set_buzzer_on": {
"name": "Set buzzer on",
"description": "Turn the buzzer on.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
}
}
},
"fan_set_buzzer_off": {
"name": "Set buzzer off",
"description": "Turn the buzzer off.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
}
}
},
"fan_set_child_lock_on": {
"name": "Set child lock on",
"description": "Turn the child lock on.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
}
}
},
"fan_set_child_lock_off": {
"name": "Set child lock off",
"description": "Turn the child lock off.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
}
}
},
"fan_set_led_brightness": {
"name": "Set LED brightness",
"description": "Set the LED brightness.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
},
"brightness": {
"name": "Brightness",
"description": "Brightness (0 = Bright, 1 = Dim, 2 = Off)"
}
}
},
"fan_set_natural_mode_on": {
"name": "Set natural mode on",
"description": "Turn the natural mode on.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
}
}
},
"fan_set_natural_mode_off": {
"name": "Set natural mode off",
"description": "Turn the natural mode off.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
}
}
},
"fan_set_oscillation_angle": {
"name": "Set oscillation angle",
"description": "Set the oscillation angle.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
},
"angle": {
"name": "Angle",
"description": "Supported angles are 30, 60, 90, 120, 140 or 150 degrees."
}
}
},
"fan_set_delay_off": {
"name": "Set delay off",
"description": "Set the scheduled turn off time.",
"fields": {
"entity_id": {
"name": "Entity ID",
"description": "Name of the Xiaomi Mi Smart Fan entity."
},
"delay_off_countdown": {
"name": "Delay off countdown",
"description": "Time in minutes. Valid values are 0, 60, 120, 180, 240, 300, 240, 300, 360, 420, 480 minutes."
}
}
}
}
}

0 comments on commit 48afb55

Please sign in to comment.