@@ -33,10 +33,16 @@ def __init__(self, flash):
3333 # --------------------------------------------------
3434
3535 def load (self ):
36- """Load configuration from the config zone."""
36+ """Load configuration from the config zone.
37+
38+ Falls back to empty config if the zone contains invalid JSON.
39+ """
3740 raw = self ._flash .read_config ()
3841 if raw :
39- self ._data = json .loads (raw )
42+ try :
43+ self ._data = json .loads (raw )
44+ except (ValueError , TypeError ):
45+ self ._data = {}
4046 else :
4147 self ._data = {}
4248
@@ -56,7 +62,10 @@ def board_revision(self):
5662
5763 @board_revision .setter
5864 def board_revision (self , value ):
59- self ._data ["rev" ] = int (value )
65+ if value is None :
66+ self ._data .pop ("rev" , None )
67+ else :
68+ self ._data ["rev" ] = int (value )
6069
6170 @property
6271 def board_name (self ):
@@ -65,7 +74,10 @@ def board_name(self):
6574
6675 @board_name .setter
6776 def board_name (self , value ):
68- self ._data ["name" ] = str (value )
77+ if value is None :
78+ self ._data .pop ("name" , None )
79+ else :
80+ self ._data ["name" ] = str (value )
6981
7082 # --------------------------------------------------
7183 # Temperature calibration
@@ -116,6 +128,8 @@ def apply_temperature_calibration(self, sensor_instance):
116128 sensor_instance: a driver instance (e.g. ``HTS221``).
117129 """
118130 class_name = type (sensor_instance ).__name__ .lower ()
131+ if class_name not in _SENSOR_KEYS :
132+ return
119133 cal = self .get_temperature_calibration (class_name )
120134 if cal is None :
121135 return
0 commit comments