@@ -274,3 +274,135 @@ tests:
274274 result = triggered and abs(t - 25.08) < 0.1
275275 expect_true : true
276276 mode : [mock]
277+
278+ # ----- Power and mode control -----
279+
280+ - name : " power_off sets sleep mode"
281+ action : script
282+ script : |
283+ i2c.clear_write_log()
284+ dev.power_off()
285+ log = i2c.get_write_log()
286+ wrote_sleep = any(reg == 0xF4 and (data[0] & 0x03) == 0x00 for reg, data in log)
287+ result = wrote_sleep
288+ expect_true : true
289+ mode : [mock]
290+
291+ - name : " power_on sets normal mode"
292+ action : script
293+ script : |
294+ i2c.clear_write_log()
295+ dev.power_on()
296+ log = i2c.get_write_log()
297+ wrote_normal = any(reg == 0xF4 and (data[0] & 0x03) == 0x03 for reg, data in log)
298+ result = wrote_normal
299+ expect_true : true
300+ mode : [mock]
301+
302+ - name : " power_off preserves oversampling bits"
303+ action : script
304+ script : |
305+ from bme280.const import OSRS_X4, OSRS_T_SHIFT, OSRS_P_SHIFT
306+ dev.set_oversampling(temperature=OSRS_X4, pressure=OSRS_X4)
307+ i2c.clear_write_log()
308+ dev.power_off()
309+ log = i2c.get_write_log()
310+ ctrl = [data[0] for reg, data in log if reg == 0xF4][-1]
311+ osrs_t = (ctrl >> 5) & 0x07
312+ osrs_p = (ctrl >> 2) & 0x07
313+ result = osrs_t == OSRS_X4 and osrs_p == OSRS_X4 and (ctrl & 0x03) == 0x00
314+ expect_true : true
315+ mode : [mock]
316+
317+ - name : " set_continuous enters normal mode"
318+ action : script
319+ script : |
320+ dev.power_off()
321+ i2c.clear_write_log()
322+ dev.set_continuous()
323+ log = i2c.get_write_log()
324+ wrote_normal = any(reg == 0xF4 and (data[0] & 0x03) == 0x03 for reg, data in log)
325+ result = wrote_normal
326+ expect_true : true
327+ mode : [mock]
328+
329+ - name : " set_continuous with standby configures both"
330+ action : script
331+ script : |
332+ from bme280.const import STANDBY_500_MS, STANDBY_SHIFT
333+ i2c.clear_write_log()
334+ dev.set_continuous(standby=STANDBY_500_MS)
335+ log = i2c.get_write_log()
336+ wrote_config = any(reg == 0xF5 for reg, data in log)
337+ wrote_normal = any(reg == 0xF4 and (data[0] & 0x03) == 0x03 for reg, data in log)
338+ result = wrote_config and wrote_normal
339+ expect_true : true
340+ mode : [mock]
341+
342+ # ----- Configuration -----
343+
344+ - name : " set_oversampling configures temperature and pressure"
345+ action : script
346+ script : |
347+ from bme280.const import OSRS_X2, OSRS_X4, OSRS_T_SHIFT, OSRS_P_SHIFT
348+ i2c.clear_write_log()
349+ dev.set_oversampling(temperature=OSRS_X2, pressure=OSRS_X4)
350+ log = i2c.get_write_log()
351+ ctrl_writes = [data[0] for reg, data in log if reg == 0xF4]
352+ ctrl = ctrl_writes[-1]
353+ osrs_t = (ctrl >> OSRS_T_SHIFT) & 0x07
354+ osrs_p = (ctrl >> OSRS_P_SHIFT) & 0x07
355+ result = osrs_t == OSRS_X2 and osrs_p == OSRS_X4
356+ expect_true : true
357+ mode : [mock]
358+
359+ - name : " set_oversampling configures humidity"
360+ action : script
361+ script : |
362+ from bme280.const import OSRS_X8
363+ i2c.clear_write_log()
364+ dev.set_oversampling(humidity=OSRS_X8)
365+ log = i2c.get_write_log()
366+ hum_writes = [data[0] for reg, data in log if reg == 0xF2]
367+ result = len(hum_writes) == 1 and hum_writes[0] == OSRS_X8
368+ expect_true : true
369+ mode : [mock]
370+
371+ - name : " set_iir_filter writes config register"
372+ action : script
373+ script : |
374+ from bme280.const import FILTER_16, FILTER_SHIFT
375+ i2c.clear_write_log()
376+ dev.set_iir_filter(FILTER_16)
377+ log = i2c.get_write_log()
378+ config_writes = [data[0] for reg, data in log if reg == 0xF5]
379+ result = len(config_writes) == 1 and ((config_writes[0] >> FILTER_SHIFT) & 0x07) == FILTER_16
380+ expect_true : true
381+ mode : [mock]
382+
383+ - name : " set_standby writes config register"
384+ action : script
385+ script : |
386+ from bme280.const import STANDBY_250_MS, STANDBY_SHIFT
387+ i2c.clear_write_log()
388+ dev.set_standby(STANDBY_250_MS)
389+ log = i2c.get_write_log()
390+ config_writes = [data[0] for reg, data in log if reg == 0xF5]
391+ result = len(config_writes) == 1 and ((config_writes[0] >> STANDBY_SHIFT) & 0x07) == STANDBY_250_MS
392+ expect_true : true
393+ mode : [mock]
394+
395+ - name : " set_iir_filter preserves standby bits"
396+ action : script
397+ script : |
398+ from bme280.const import STANDBY_500_MS, STANDBY_SHIFT, FILTER_4, FILTER_SHIFT
399+ dev.set_standby(STANDBY_500_MS)
400+ i2c.clear_write_log()
401+ dev.set_iir_filter(FILTER_4)
402+ log = i2c.get_write_log()
403+ config = [data[0] for reg, data in log if reg == 0xF5][-1]
404+ standby = (config >> STANDBY_SHIFT) & 0x07
405+ filt = (config >> FILTER_SHIFT) & 0x07
406+ result = standby == STANDBY_500_MS and filt == FILTER_4
407+ expect_true : true
408+ mode : [mock]
0 commit comments