Localtuya state change

I have a Number entity created by localtuya. If I manually change the number value, localtuya sends a command to the device to update it.

However, if I change the number value using pyscript, localtuya does not send a command. A state_changed event is fired, but local_tuya does not appear to respond to it.

How can I, from pyscript, request localtuya to send a command to the device?

I’ve discovered that the code:

number.set_value (entity_id='x', value=123)

works, but my original code:

state.set ('x', 123)

doesn’t.

If someone can explain why, I’d be grateful.