[docs]classChillerBot(BaseBot):"""Manages the FPS chiller."""def__init__(self,fps:FPS):self.chiller_config=config.get("chiller",{})self.temperature:bool|float=self.chiller_config.get("temperature",False)self.flow:bool|float=self.chiller_config.get("flow",False)super().__init__(fps)asyncdef_loop(self):"""Sets the chiller set point temperature."""chiller=Chiller.create()assertchillerisnotNonewhileTrue:awaitself._set_temperature(chiller)awaitself._set_flow(chiller)awaitasyncio.sleep(60)asyncdef_set_temperature(self,chiller:Chiller):"""Sets the temperature set point."""dev_name="TEMPERATURE_USER_SETPOINT"dev=chiller.get_device(dev_name)ifself.temperatureisFalseorself.temperatureisNone:returnifself.temperature=="auto":ifnotisinstance(self.ieb,IEB)orself.ieb.disabledisTrue:returnfailed:bool=False# Try up to 10 times since sometimes setting the temperature fails.for_inrange(10):failed=Falsetry:current_setpoint=(awaitdev.read())[0]# If we are maintaining a fixed temperature, check if we# need to reset the set point and exit.ifself.temperatureisnotTrueandself.temperature!="auto":ifabs(current_setpoint-self.temperature)>0.1:awaitdev.write(int(self.temperature*10))self.notify(f"Setting chiller to {self.temperature} C",logging.DEBUG,)breakassertisinstance(self.ieb,IEB)andself.ieb.disabledisFalseambient_temp=(awaitself.ieb.read_device("T3"))[0]rh=(awaitself.ieb.read_device("RH3"))[0]# Dewpoint temperature.t_d=ambient_temp-(100-rh)/5.0# What follows is if we are setting the set point# based on the ambient temperature.# Calculate the new set point temperature and write it# to the device if it's different than the current one.# New set point is two degC below ambient clipped to 1 degC# and above the dew point depression region.new_temp=ambient_temp-2ifnew_temp<=1:new_temp=1ifnew_temp<(t_d+3):new_temp=t_d+3# Round to closest 0.5new_temp=round(new_temp*2)/2.0delta_temp=abs(current_setpoint-new_temp)ifdelta_temp>0.1:awaitdev.write(int(new_temp*10))self.notify(f"Setting chiller to {new_temp} C",logging.DEBUG)breakexceptException:failed=Trueawaitasyncio.sleep(2)continueiffailedisTrue:self.notify("Failed setting chiller temperature.",level=logging.ERROR)asyncdef_set_flow(self,chiller:Chiller):"""Sets the flow set point."""dev_name="FLOW_USER_SETPOINT"dev=chiller.get_device(dev_name)ifself.flowisTrueorself.flow=="auto":self.flow=self.chiller_config.get("flow",False)ifself.flowisFalseorself.flowisNone:returnfailed:bool=False# Try up to 10 times since sometimes setting the flow fails.for_inrange(10):failed=Falsetry:current_setpoint=(awaitdev.read())[0]ifisinstance(self.flow,(float,int)):ifabs(current_setpoint-self.flow)>0.1:awaitdev.write(int(self.flow*10))self.notify(f"Setting chiller flow to {self.flow:.1f} gpm.",level=logging.DEBUG,)else:self.notify(f"Invalid chiller set point {self.flow!r}.",level=logging.WARNING,)breakexceptException:failed=Trueawaitasyncio.sleep(2)continueiffailedisTrue:self.notify("Failed setting chiller flow.",level=logging.ERROR)