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

I can't seem to overwrite calibration decoration when I inherit on_get from SimpleSCPIEntity #144

Open
raphaelcervantes opened this issue Aug 16, 2021 · 0 comments

Comments

@raphaelcervantes
Copy link
Contributor

Sorry, I don't have time to write something thoughtful. I'm going to paste the slack conversation related to this issue because it's better than nothing.

Raphael Cervantes 10:59 AM
@ben LaRoque I'm trying to extend SimpleSCPIEntity such that on_get has a custom calibration

from dripline.core import Entity, calibrate, ThrowReply
from dripline.implementations import SimpleSCPIEntity
import logging
from .power_detector_calibration import zx47_50_cal

logger = logging.getLogger(__name__)

__all__ = []

__all__.append("PowerDetectorEntity")
class PowerDetectorEntity(SimpleSCPIEntity):
    '''
    Entity with power detector calibration
    '''

    @calibrate([zx47_50_cal])
    def on_get(self):

What should go in the body of on_get if it's the same as SimpleSCPIEntity

Ben LaRoque 11:03 AM
ummm:

def on_get(self):
    return super().on_get()

(edited)
11:04
should be the same as:

def on_get(self):
    return SimpleSCPIEntity.on_get(self)

Raphael Cervantes 11:05 AM
ok. dope
11:05
I was about to just copy what was in SimpleSCPIEntity, which would have been bad OOP

Ben LaRoque 11:07 AM
the first one uses the class method resolution order to find the next on_get implementation, the latter specifically uses the one that is first in the MRO of SimpleSCPIEntity; here those should be the same, but there could be a time when there’s a subtle difference and you care
11:07
(like if you have multiple inheritance)

Raphael Cervantes 11:08 AM
ohhh
11:08
got it

Raphael Cervantes 11:42 AM
@ben LaRoque I'm getting a name error when I run this get command with the custom calibration and I don't understand why

2021-08-16T18:38:10[INFO    ] dripline.implementations.ethernet_scpi_service(172) -> sync: 'MEASure:VOLTage:DC?\r\n' -> '-7.55700000E-06'
2021-08-16T18:38:10[DEBUG   ] dripline.implementations.ethernet_scpi_service(143) -> should return:
-7.55700000E-06
2021-08-16T18:38:10[DEBUG   ] dripline.implementations.entity_endpoints(50) -> raw result is: -7.55700000E-06
2021-08-16T18:38:10[DEBUG   ] dripline.core.calibrate(30) -> attempting to calibrate
2021-08-16T18:38:10[DEBUG   ] dripline.core.calibrate(43) -> formatted cal is:
zx47_50_cal(-7.55700000E-06)
NameError
   zx47_50_cal(-7.55700000E-06)
name 'zx47_50_cal' is not defined
this is where the calibration function is defined: https://github.com/axiondarkmatterexperiment/dripline-orpheus/blob/ad12b0d05cfff7b[…]/extensions/power_detector_entity/power_detector_calibration.py
this is where it decorates the on_get function: https://github.com/axiondarkmatterexperiment/dripline-orpheus/blob/ad12b0d05cfff7b[…]e5e/dripline/extensions/power_detector_entity/power_detector.py

did I implement this incorrectly?

power_detector_calibration.py
https://github.com/axiondarkmatterexperiment/dripline-orpheus|axiondarkmatterexperiment/dripline-orpheusaxiondarkmatterexperiment/dripline-orpheus | Added by GitHub

power_detector.py
https://github.com/axiondarkmatterexperiment/dripline-orpheus|axiondarkmatterexperiment/dripline-orpheusaxiondarkmatterexperiment/dripline-orpheus | Added by GitHub

Raphael Cervantes 11:59 AM
here is my endpoint definiton:

    endpoints:
      - name: power_monitor_voltage
        module: PowerDetectorEntity
        base_str: MEASure:VOLTage:DC
        calibration: "zx47_50_cal({})"
        log_routing_key_prefix: sensor_double_precision

Raphael Cervantes 12:13 PM
I explicitly defined on_get and have gotten further https://github.com/axiondarkmatterexperiment/dripline-orpheus/blob/95f88fd0ae03363[…]8cd/dripline/extensions/power_detector_entity/power_detector.py
I'm guessing the inheritence caused conflicting calibration decorations?

power_detector.py
@calibrate([zx47_50_cal])
https://github.com/axiondarkmatterexperiment/dripline-orpheus|axiondarkmatterexperiment/dripline-orpheusaxiondarkmatterexperiment/dripline-orpheus | Added by GitHub

Raphael Cervantes 12:31 PM
ok I have it working now
12:31
but I couldn't use inheritence
12:32
maybe there's a way to override the calibration decoration from the base class?

Ben LaRoque 12:33 PM
oh… um
12:33
that may be a design problem, would need to think about it (edited)
12:33
(dripline side, not your side)

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

1 participant