Ejemplo n.º 1
0
 def get_data_from_web(self):
     logger.debug("Retrieve data from web.")
     try:
         content = urllib2.urlopen(WEATHER_URL, timeout=5)
         last_line = content.readlines()[-1].split()
         wind_speed = float(last_line[7])
         outside_temp = float(last_line[2])
     except (ValueError, IOError, urllib2.HTTPError, urllib2.URLError):
         logger.error(
             "Unable to get data from the website. Reading previous value from the DB."
         )
         with db.session_scope() as session:
             wind_speed, outside_temp = session.query(
                 db.History.wind_speed, db.History.outside_temp).order_by(
                     desc(db.History.id)).first()
     if outside_temp != self._outside_temp:
         socketio_client.send({
             "event": "misc",
             "message": {
                 "outside_temp": outside_temp
             }
         })
         self._outside_temp = outside_temp
         self._wind_speed = wind_speed
     return {"outside_temp": outside_temp, "wind_speed": wind_speed}
Ejemplo n.º 2
0
 def _update_settings(self, name, value):
     with db.session_scope() as session:
         property_ = session.query(db.Settings).first()
         setattr(property_, name, value)
     if name == "cascade_time":
         value /= 60
     if name != "mode_switch_timestamp":
         socketio_client.send({"event": "misc", "message": {name: value}})
Ejemplo n.º 3
0
 def return_temp(self):
     return_temp = self._read_temperature_sensor(cfg.sensors.in_id)
     if return_temp != self._return_temp:
         socketio_client.send({
             "event": "misc",
             "message": {
                 "return_temp": return_temp
             }
         })
         self._return_temp = return_temp
     return return_temp
Ejemplo n.º 4
0
 def water_out_temp(self):
     water_out_temp = self._read_temperature_sensor(cfg.sensors.out_id)
     if water_out_temp != self._water_out_temp:
         socketio_client.send({
             "event": "misc",
             "message": {
                 "water_out_temp": water_out_temp
             }
         })
         self._water_out_temp = water_out_temp
     return water_out_temp
Ejemplo n.º 5
0
 def _send_socketio_message(self,
                            event=None,
                            status=None,
                            switched_timestamp=None,
                            manual_override=None):
     if switched_timestamp:
         switched_timestamp = switched_timestamp.strftime("%B %d, %I:%M %p")
     socketio_client.send({
         "event": event,
         "message": {
             "status": status,
             "device": self.number,
             "switched_timestamp": switched_timestamp,
             "manual_override": manual_override
         }
     })
Ejemplo n.º 6
0
 def read_modbus_data(self):
     boiler_stats = {
         "system_supply_temp": 0,
         "outlet_temp": 0,
         "inlet_temp": 0,
         "flue_temp": 0,
         "cascade_current_power": 0,
         "lead_firing_rate": 0
     }
     for i in range(1, 4):
         try:
             with modbus_session() as modbus:
                 # Read one register from 40006 address
                 # to get System Supply Temperature
                 # Memory map for the boiler is here on page 8:
                 # http://www.lochinvar.com/_linefiles/SYNC-MODB%20REV%20H.pdf
                 hregs = modbus.read_holding_registers(6,
                                                       count=1,
                                                       unit=cfg.modbus.unit)
                 # Read 9 registers from 30003 address
                 iregs = modbus.read_input_registers(3,
                                                     count=9,
                                                     unit=cfg.modbus.unit)
                 boiler_stats = {
                     "system_supply_temp":
                     c_to_f(hregs.getRegister(0) / 10.0),
                     "outlet_temp": c_to_f(iregs.getRegister(5) / 10.0),
                     "inlet_temp": c_to_f(iregs.getRegister(6) / 10.0),
                     "flue_temp": c_to_f(iregs.getRegister(7) / 10.0),
                     "cascade_current_power": float(iregs.getRegister(3)),
                     "lead_firing_rate": float(iregs.getRegister(8))
                 }
         except (AttributeError, IndexError):
             logger.warning(
                 "Attempt {}. Modbus answer is empty, retrying.".format(i))
             time.sleep(1)
         except (OSError, ModbusException, serial.SerialException):
             logger.exception("Cannot connect to modbus")
             break
         else:
             logger.info("Attempt {}. {}".format(i, boiler_stats))
             break
     else:
         logger.error("Couldn't read modbus stats")
     self._update_value_in_db(**boiler_stats)
     socketio_client.send({"event": "misc", "message": boiler_stats})
Ejemplo n.º 7
0
 def baseline_setpoint(self):
     wind_chill = int(round(self.outside_temp))
     if wind_chill < 11:
         baseline_setpoint = 100
     else:
         with db.session_scope() as session:
             baseline_setpoint, = session.query(
                 db.SetpointLookup.setpoint).filter(
                     db.SetpointLookup.wind_chill == wind_chill).first()
     if baseline_setpoint != self._baseline_setpoint:
         socketio_client.send({
             "event": "misc",
             "message": {
                 "baseline_setpoint": baseline_setpoint
             }
         })
         self._baseline_setpoint = baseline_setpoint
     return baseline_setpoint
Ejemplo n.º 8
0
 def effective_setpoint(self):
     "Calculate setpoint from wind_chill."
     if self.mode in (WINTER, TO_WINTER):
         effective_setpoint = (self.tha_setpoint +
                               self.setpoint_offset_winter)
     elif self.mode in (SUMMER, TO_SUMMER):
         effective_setpoint = (self.tha_setpoint +
                               self.setpoint_offset_summer)
     effective_setpoint = self._constrain_effective_setpoint(
         effective_setpoint)
     if effective_setpoint != self._effective_setpoint:
         socketio_client.send({
             "event": "misc",
             "message": {
                 "effective_setpoint": effective_setpoint
             }
         })
         self._effective_setpoint = effective_setpoint
     return effective_setpoint
Ejemplo n.º 9
0
 def tha_setpoint(self):
     if self.wind_chill_avg < 71:
         temperature_history_adjsutment = 0
     else:
         with db.session_scope() as session:
             temperature_history_adjsutment, = session.query(
                 db.SetpointLookup.setpoint_offset).filter(
                     db.SetpointLookup.avg_wind_chill ==
                     self.wind_chill_avg).first()
     tha_setpoint = self.baseline_setpoint - temperature_history_adjsutment
     if tha_setpoint != self._tha_setpoint:
         socketio_client.send({
             "event": "misc",
             "message": {
                 "tha_setpoint": tha_setpoint
             }
         })
         self._tha_setpoint = tha_setpoint
     return tha_setpoint