diff --git a/device/device.py b/device/device.py index ac5445670f9f9de796b52b38abd20fbd772a863a..ea63a37bcfcf6dfe4e75400e085a91de54c42986 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()