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

How to set read-only property of simulated device(eg. magnet-sensor) to test automated rules? #1999

Open
ifcarpediem opened this issue Jan 4, 2025 · 1 comment

Comments

@ifcarpediem
Copy link

I want to test some automated rules, so I need to change some properties of sensors, but they are read-only.

Examples: illumination_sensor

miiocli device --ip 127.0.0.1 --token 00000000000000000000000000000000 raw_command dump_properties '{"siid": 2}'

Running command raw_command
[{'siid': 2, 'piid': 1, 'prop': 'Illumination', 'value': 80073}]

miiocli device --ip 127.0.0.1 --token 00000000000000000000000000000000 raw_command set_properties '[{"siid":2,"piid":1, "value": 1}]'

Running command raw_command
ERROR:miio.click_common:Exception: {'code': -3, 'error': "Exception <class 'pydantic.v1.error_wrappers.ValidationError'>: 1 validation error for SimulatedMiotProperty\ncurrent_value\n Tried to set read-only property (type=value_error)"}
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/miio/click_common.py", line 54, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1082, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1697, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1697, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1443, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 788, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/miio/click_common.py", line 305, in wrap
result = kwargs["result"] = func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/decorators.py", line 92, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 788, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/miio/click_common.py", line 270, in command_callback
return miio_command.call(miio_device, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/miio/click_common.py", line 218, in call
return method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/miio/click_common.py", line 185, in _wrap
return func(self, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/miio/device.py", line 141, in raw_command
return self.send(command, parameters)
File "/usr/local/lib/python3.9/site-packages/miio/device.py", line 122, in send
return self._protocol.send(
File "/usr/local/lib/python3.9/site-packages/miio/miioprotocol.py", line 215, in send
self._handle_error(payload["error"])
File "/usr/local/lib/python3.9/site-packages/miio/miioprotocol.py", line 276, in _handle_error
raise DeviceError(error)
miio.exceptions.DeviceError: {'code': -3, 'error': "Exception <class 'pydantic.v1.error_wrappers.ValidationError'>: 1 validation error for SimulatedMiotProperty\ncurrent_value\n Tried to set read-only property (type=value_error)"}

@rytilahti
Copy link
Owner

That is not currently possible without changing the code, but you could change it manually for your testing:

if MiotAccess.Write not in values["access"]:
raise ValueError("Tried to set read-only property")

I can see that being able to set values (also for read-only) is useful, so we could find a solution (e.g., adding an option to allow this, or have a separate method to set read-onlys). What do you think?

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

2 participants