Closed MikeFalowski closed 2 years ago
Hi @MikeFalowski
I've never tried that before, but it seems to be possible. I see fisallowed
it mentioned in the attribute
class docstring, which ends up as a table readthedocs here: https://pytango.readthedocs.io/en/stable/server_api/server.html#tango.server.attribute
class MyDevice(Device):
def init_device(self):
super(MyDevice, self).init_device()
self.position_value = 0
@attribute(dtype=int, fisallowed="custom_position_allowed")
def position(self):
return self.position_value
def custom_position_allowed(self, req_type):
return self.get_state() == DevState.ON
The parameter can be either a string or a reference to the function.
Hi @ajoubertza,
I checked it and in attribute it looks like it's working. The only thing is that I missed earlier req_type
argument. I think it would be nice to put example in the High level server API docs.
Unfortunately, when I try to use it in a command, I've got:
TypeError: command() got an unexpected keyword argument 'fisallowed' So I guess, it is a proposal for having keyargument
fisallowed
in command.
@MikeFalowski Sorry, I completely misunderstood your question! You were asking about commands, not attributes.
It it not implemented for commands. It should be possible to add fisallowed
on the Python layer, but would take some effort. What is the use case for this?
I think it would be nice to put example in the High level server API docs. Yes, it would. Please contribute a pull request. You could add it to the PowerSupply example in https://github.com/tango-controls/pytango/blob/develop/doc/howto.rst#write-a-server.
Hi @MikeFalowski,
Not sure if you explicitly want an fisallowed for commands but you can already do is_<command>_allowed
. The only downside here is you can't make a general method.
Another alternative would be to create your own @is_command_allowed
decorator.
def is_Standby_allowed(self):
return self.get_state() in [tango.DevState.ON]
@command
def Standby(self):
# PROTECTED REGION ID(SatFrqCtrl.Standby) ENABLED START #
self.set_state(DevState.STANDBY)
# PROTECTED REGION END #
def is_On_allowed(self):
return self.get_state() in [tango.DevState.STANDBY]
@command
def On(self):
# PROTECTED REGION ID(SatFrqCtrl.On) ENABLED START #
self.set_state(DevState.ON)
# PROTECTED REGION END #
In High Level Server API, instead of creating strict
is_<attr>_allowed
, there is possibility to define method in afisallowed
keyargument in the attribute and pipe decorator.Unfortunately, I haven't found anything in documentation about that for commands. Is it not implemented? I think, it would be nice to have it too for commands.