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

wrap method for ntenum does not handle changes to alarm or descriptor #153

Open
kurup opened this issue Aug 20, 2024 · 1 comment
Open

Comments

@kurup
Copy link

kurup commented Aug 20, 2024

I've been looking at implementing NTEnum PVs using p4p and I've run into an issue with setting the alarm and descriptor parts of the struct failing when using a put operation from a client. It looks like this has not been implemented yet in the wrap method and only setting the index or choices is supported. The following change to the wrap method fixes this:

    def wrap(self, value, choices=None, **kws):
        """Pack python value into Value
        """
        V = self.type()
        if choices is not None:
            V['value.choices'] = choices
        if isinstance(value, dict):
            for key in value:
                V[key] = value[key]
        elif isinstance(value, Value):
            for key in value.changedSet():
                V[key] = value[key]
        else:
            # index or string
            self.assign(V, value)

        if V.changed('value.choices'):
            self._choices = V['value.choices']

        return self._annotate(V, **kws)

It'd be good to include this in master if you're happy with this fix.

@m2es3h
Copy link

m2es3h commented Aug 20, 2024

I recently had a similar issue when initialising an NTEnum struct (see this PR: #154). I think the ideal fix is to make it as similar to the NRScalar wrap() code as possible, something like this:

        if isinstance(value, Value):
            V = value
        elif isinstance(value, ntwrappercommon):
            kws.setdefault('timestamp', value.timestamp)
            V = value.raw
        elif isinstance(value, dict):
            V = self.Value(self.type, value)
        else:
            # index or string (use NTEnum.assign() here, different from NTScalar)
            self.assign(V, value)

        self._annotate(V, **kws)

However, the code above would break the existing functionality of setting index/choices like this initial={'index': N, 'choices': [...]}.

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