Skip to content

Commit 286fe45

Browse files
committed
update write_protected.setter
1 parent 2f67002 commit 286fe45

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

adafruit_fram.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ def write_protected(self):
105105
"""
106106
return self._wp if self._wp_pin is None else self._wp_pin.value
107107

108-
@write_protected.setter
109-
def write_protected(self, value):
110-
self._wp = value
111-
if not self._wp_pin is None:
112-
self._wp_pin.value = value
113-
114108
def __len__(self):
115109
""" The maximum size of the current FRAM chip. This is the highest
116110
register location that can be read or written to.
@@ -261,6 +255,15 @@ def _write(self, start_register, data, wraparound=False):
261255
buffer[2] = data[i]
262256
i2c.write(buffer)
263257

258+
# pylint: disable=no-member
259+
@FRAM.write_protected.setter
260+
def write_protected(self, value):
261+
if value not in (True, False):
262+
raise ValueError("Write protected value must be 'True' or 'False'.")
263+
self._wp = value
264+
if not self._wp_pin is None:
265+
self._wp_pin.value = value
266+
264267
# the following pylint disables are related to the '_SPI_OPCODE' consts, the super
265268
# class setter '@FRAM.write_protected.setter', and pylint not being able to see
266269
# 'spi.write()' in SPIDevice. Travis run for reference:
@@ -346,6 +349,8 @@ def write_protected(self, value):
346349
# While it is possible to protect block ranges on the SPI chip,
347350
# it seems superfluous to do so. So, block protection always protects
348351
# the entire memory (BP0 and BP1).
352+
if value not in (True, False):
353+
raise ValueError("Write protected value must be 'True' or 'False'.")
349354
self._wp = value
350355
write_buffer = bytearray(2)
351356
write_buffer[0] = _SPI_OPCODE_WRSR

0 commit comments

Comments
 (0)