Gate valve class

Gate valves are children of the parent Valve class, as shown in the following code example:

# valve.py (part 8)
1 class Gate(Valve): 2 """Open/closed valve.""" 3 def read_position(self): 4 """Identify the position of the valve.""" 5 if self.position == 0: 6 return "{name} is closed.".format(name=self.name) 7 elif self.position == 100: 8 return "{name} is open.".format(name=self.name) 9 else: # bad condition 10 return "Warning! {name} is partially open.".format(name=self.name) 11 12 def turn_handle(self, new_position): 13 """Change the status of the valve.""" 14 if new_position == 0: 15 self.close() 16 elif new_position == 100: 17 self.open() 18 else: # Shouldn't get here 19 return "Warning: Invalid valve position."

The Gate subclass inherits everything from the Valve parent class. The only new methods it provides are read_position() and turn_handle(). As a gate valve is either open or closed (it doesn't affect fluid flow until more than 70% closed), we only need to know whether the valve is fully open or closed. In addition, when operating the valve, we only need to open or close it, so turn_handle() only accepts those two values; all others result in an error.