Skip to content

Commit

Permalink
🔧 fix for miot action (#2059)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Dec 13, 2024
1 parent 229fa11 commit 0e5e42d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions custom_components/xiaomi_miot/core/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ def decode(self, device: 'Device', payload: dict, value):
super().decode(device, payload, value)

def encode(self, device: 'Device', payload: dict, value):
if self.prop and self.prop.value_list and isinstance(value, str):
value = self.prop.list_value(value)
if self.prop and isinstance(value, str):
if self.prop.value_list or self.prop.value_range:
value = self.prop.list_value(value)
elif self.prop.is_integer:
value = int(value)
ins = value if isinstance(value, list) else [] if value is None else [value]
_, s, p = self.mi.split('.')
payload['method'] = 'action'
Expand Down
3 changes: 2 additions & 1 deletion custom_components/xiaomi_miot/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ def encode(self, value: dict) -> dict:
async def async_write(self, payload: dict):
"""Send command to device."""
data = self.encode(payload)
self.log.info('Device write data: %s', [payload, data])
result = None
method = data.get('method')

Expand Down Expand Up @@ -652,7 +653,7 @@ async def async_write(self, payload: dict):
if self.cloud and cloud_param:
result = await self.cloud.async_do_action(cloud_param)

self.log.info('Device write: %s', [payload, data, result])
self.log.info('Device write result: %s', [payload, result])
if result:
self.dispatch(payload)
return result
Expand Down
1 change: 1 addition & 0 deletions custom_components/xiaomi_miot/core/device_customizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@
'select_properties': 'ledboard_model',
'number_properties': 'ledboard_brightness,ledboard_sun,ledboard_color,ledboard_stream,ledboard_speed,'
'pump_flux,feed_num',
'select_actions': 'set_feed_single',
'light_services': 'fish_tank',
'power_property': 'fish_tank.on',
'mode_property': 'ledboard_model',
Expand Down
1 change: 1 addition & 0 deletions custom_components/xiaomi_miot/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def on_init(self):
self._attr_options.insert(0, '')
if lst := getattr(self.conv, 'options', None):
self._attr_options = lst
self._attr_available = True

def get_state(self) -> dict:
return {self.attr: self._attr_current_option}
Expand Down

0 comments on commit 0e5e42d

Please sign in to comment.