Skip to content

Commit

Permalink
add missing __enter__ and __exit__
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickael committed Oct 1, 2020
1 parent 58e0a01 commit 7bf42ea
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions GreenPonik_BME280/BME280.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7bf42ea

Please sign in to comment.