tango-controls/pytango

Dynamic attributes with write methods

Closed this issue · 4 comments

Hello,

I'm wondering if there is a simple way to implement a writing method for dynamically generated attribute that takes the value as argument (or allows for user input).

So far I've been using Attr's get_write_value() method - example below:

def write_analogOutput(self, attr) -> None:
        elem = attr.get_name().split("_")[1]
        value = attr.get_write_value()
        self.write_register(elem, self.decode_value(value, elem, `0))

...but the docs say it's deprecated, so I'm looking for another solution.

I'd be grateful for any help.

Hi @TNoga0

I'm not sure. Can you provide a link to where it says it is deprecated?

I recently added a test that uses that method too...

OK, I have found the deprecation note:

pytango/tango/device_server.py

Lines 1984 to 1986 in 70ef4df

document_method("get_write_value", """
get_write_value(self, lst) -> None <= DEPRECATED
get_write_value(self, extract_as=ExtractAs.Numpy) -> obj

Note that there are two versions of the function, only the first one is deprecated.

Basically it says DON'T do it this way:

def write_analogOutput(self, attr) -> None:
    elem = attr.get_name().split("_")[1]
    deprecated_way_to_get_values = []
    attr.get_write_value(deprecated_way_to_get_values)
    value = deprecated_way_to_get_values[0]
    self.write_register(elem, self.decode_value(value, elem, 0))

@TNoga0 Does this answer your question?

No response, so closing old ticket.