From 34e7c2d0249ba1e0a6d064759ac0ea32468db3fb Mon Sep 17 00:00:00 2001 From: Matt Grau <graum@phys.ethz.ch> Date: Tue, 13 Jul 2021 13:55:36 +0200 Subject: [PATCH] update device class to use decorators --- device/device.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/device/device.py b/device/device.py index ac54456..ea63a37 100644 --- a/device/device.py +++ b/device/device.py @@ -20,9 +20,17 @@ class Device: # write voltage to device self.__voltage = new_voltage + @property + def voltage(self): + return self._get_voltage() + + @voltage.setter + def voltage(self, new_voltage): + self._set_voltage(new_voltage) + def _get_current(self): # read current from device - current = self.__curent + current = self.__current self.current = current return current @@ -30,8 +38,22 @@ class Device: # write current to device self.__current = new_current + @property + def current(self): + return self._get_current() + + @current.setter + def current(self, new_current): + self._set_current(new_current) + def _calculate_resistance(self): + if self.current == 0: + return float('inf') current = self.current voltage = self.voltage resistance = voltage / current return resistance + + @property + def resistance(self): + return self._calculate_resistance() -- GitLab