We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Functions warning_alert_threshold and critical_alert_threshold should be in channel's class. Here's patch moving them:
warning_alert_threshold
critical_alert_threshold
--- old.py 2025-01-09 21:33:42.763661755 +0100 +++ new.py 2025-01-09 21:38:14.906018218 +0100 @@ -180,6 +180,56 @@ self._parent._shunt_resistance[self._channel] = value @property + def critical_alert_threshold(self) -> float: + """Critical-Alert threshold in amperes + + Returns: + float: The current critical alert threshold in amperes. + """ + if self._channel > 2: + raise ValueError("Invalid channel number. Must be 0, 1, or 2.") + + reg_addr = CRITICAL_ALERT_LIMIT_CH1 + 2 * self._channel + result = self._parent._read_register(reg_addr, 2) + threshold = int.from_bytes(result, "big") + return (threshold >> 3) * 40e-6 / self.shunt_resistance + + @critical_alert_threshold.setter + def critical_alert_threshold(self, current: float) -> None: + if self._channel > 2: + raise ValueError("Invalid channel number. Must be 0, 1, or 2.") + + threshold = int(current * self.shunt_resistance / 40e-6 * 8) + reg_addr = CRITICAL_ALERT_LIMIT_CH1 + 2 * self._channel + threshold_bytes = threshold.to_bytes(2, "big") + self._parent._write_register(reg_addr, threshold_bytes) + + @property + def warning_alert_threshold(self) -> float: + """Warning-Alert threshold in amperes + + Returns: + float: The current warning alert threshold in amperes. + """ + if self._channel > 2: + raise ValueError("Invalid channel number. Must be 0, 1, or 2.") + + reg_addr = WARNING_ALERT_LIMIT_CH1 + self._channel + result = self._parent._read_register(reg_addr, 2) + threshold = int.from_bytes(result, "big") + return threshold / (self.shunt_resistance * 8) + + @warning_alert_threshold.setter + def warning_alert_threshold(self, current: float) -> None: + if self._channel > 2: + raise ValueError("Invalid channel number. Must be 0, 1, or 2.") + + threshold = int(current * self.shunt_resistance * 8) + reg_addr = WARNING_ALERT_LIMIT_CH1 + self._channel + threshold_bytes = threshold.to_bytes(2, "big") + self._parent._write_register(reg_addr, threshold_bytes) + + @property def current_amps(self) -> float: """Returns the current in amperes. @@ -363,56 +413,6 @@ self._write_register(CONFIGURATION, config) @property - def critical_alert_threshold(self) -> float: - """Critical-Alert threshold in amperes - - Returns: - float: The current critical alert threshold in amperes. - """ - if self._channel > 2: - raise ValueError("Invalid channel number. Must be 0, 1, or 2.") - - reg_addr = CRITICAL_ALERT_LIMIT_CH1 + 2 * self._channel - result = self._parent._read_register(reg_addr, 2) - threshold = int.from_bytes(result, "big") - return (threshold >> 3) * 40e-6 / self.shunt_resistance - - @critical_alert_threshold.setter - def critical_alert_threshold(self, current: float) -> None: - if self._channel > 2: - raise ValueError("Invalid channel number. Must be 0, 1, or 2.") - - threshold = int(current * self.shunt_resistance / 40e-6 * 8) - reg_addr = CRITICAL_ALERT_LIMIT_CH1 + 2 * self._channel - threshold_bytes = threshold.to_bytes(2, "big") - self._parent._write_register(reg_addr, threshold_bytes) - - @property - def warning_alert_threshold(self) -> float: - """Warning-Alert threshold in amperes - - Returns: - float: The current warning alert threshold in amperes. - """ - if self._channel > 2: - raise ValueError("Invalid channel number. Must be 0, 1, or 2.") - - reg_addr = WARNING_ALERT_LIMIT_CH1 + self._channel - result = self._parent._read_register(reg_addr, 2) - threshold = int.from_bytes(result, "big") - return threshold / (self.shunt_resistance * 8) - - @warning_alert_threshold.setter - def warning_alert_threshold(self, current: float) -> None: - if self._channel > 2: - raise ValueError("Invalid channel number. Must be 0, 1, or 2.") - - threshold = int(current * self.shunt_resistance * 8) - reg_addr = WARNING_ALERT_LIMIT_CH1 + self._channel - threshold_bytes = threshold.to_bytes(2, "big") - self._parent._write_register(reg_addr, threshold_bytes) - - @property def flags(self) -> int: """Flag indicators from the Mask/Enable register.
The text was updated successfully, but these errors were encountered:
I have added the pull request #3 with the changes.
Sorry, something went wrong.
No branches or pull requests
Functions
warning_alert_threshold
andcritical_alert_threshold
should be in channel's class.Here's patch moving them:
The text was updated successfully, but these errors were encountered: