From 7bf42eac96b2e4e6b626f08d7ded1a58efce66ce Mon Sep 17 00:00:00 2001
From: Mickael <mickael.lehoux@greenponik.com>
Date: Thu, 1 Oct 2020 19:02:00 +0200
Subject: [PATCH] add missing __enter__ and __exit__

---
 GreenPonik_BME280/BME280.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/GreenPonik_BME280/BME280.py b/GreenPonik_BME280/BME280.py
index 94fd283..8916898 100644
--- a/GreenPonik_BME280/BME280.py
+++ b/GreenPonik_BME280/BME280.py
@@ -25,6 +25,17 @@ def __init__(self, bus=DEFAULT_BUS, addr=DEFAULT_ADDR):
         self._addr = addr
         self._debug = False
 
+    def __enter__(self):
+        """Context manager enter function."""
+        # Just return this object so it can be used in a with statement, like
+        # with WaterPumpDriver(bus=1, addr=100) as driver:
+        #     # do stuff!
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        """Context manager exit function, ensures resources are cleaned up."""
+        return False  # Don't suppress exceptions.
+
     @property
     def bus(self):
         return self._bus