Package net.homeip.mleclerc.omnilinkbbclient.model

Source Code of net.homeip.mleclerc.omnilinkbbclient.model.ThermostatModel

package net.homeip.mleclerc.omnilinkbbclient.model;

import java.rmi.RemoteException;

import net.homeip.mleclerc.omnilinkbbclient.OmniLinkBBClient;
import net.homeip.mleclerc.omnilinkbbclient.stubs.AegisWebService;
import net.homeip.mleclerc.omnilinkbbclient.stubs.FanMode;
import net.homeip.mleclerc.omnilinkbbclient.stubs.HoldMode;
import net.homeip.mleclerc.omnilinkbbclient.stubs.SystemMode;
import net.homeip.mleclerc.omnilinkbbclient.stubs.ThermostatStatusResponse;

public class ThermostatModel {
  private AegisWebService client;
  private ThermostatStatusResponse cachedThermostatStatus;
 
  public ThermostatModel(AegisWebService client) {
    this.client = client;
  }
 
  public double getCurrentTemperature() {
    return getThermostatStatusResponse().getCurrentTemperature();
  }
 
  public double getMinTemperature() {
    return getThermostatStatusResponse().getLowSetPoint();
  }

  public double getMaxTemperature() {
    return getThermostatStatusResponse().getHighSetPoint();
  }

  public FanMode getFanMode() {
    return getThermostatStatusResponse().getFanMode();
  }

  public HoldMode getHoldMode() {
    return getThermostatStatusResponse().getHoldMode();
  }

  public SystemMode getSystemMode() {
    return getThermostatStatusResponse().getSystemMode();
  }

  public boolean setMinTemperature(final double lowSetPoint) {
    try {
      return OmniLinkBBClient.execute(new OmniLinkBBClient.BoolExecution() {
        public boolean boolExecute() throws RemoteException {
          return client.setThermostatLowSetPoint(lowSetPoint);
        }
      });
    } catch(OmniLinkBBClient.ExecutionException ex) {
      return false;
   
  }

  public boolean setMaxTemperature(final double highSetPoint) {
    try {
      return OmniLinkBBClient.execute(new OmniLinkBBClient.BoolExecution() {
        public boolean boolExecute() throws RemoteException {
          return client.setThermostatHighSetPoint(highSetPoint);
        }
      });
    } catch(OmniLinkBBClient.ExecutionException ex) {
      return false;
   
  }

  public boolean setFanMode(final FanMode fanMode) {
    try {
      return OmniLinkBBClient.execute(new OmniLinkBBClient.BoolExecution() {
        public boolean boolExecute() throws RemoteException {
          return client.setThermostatFanMode(fanMode);
        }
      });
    } catch(OmniLinkBBClient.ExecutionException ex) {
      return false;
   
  }

  public boolean setHoldMode(final HoldMode holdMode) {
    try {
      return OmniLinkBBClient.execute(new OmniLinkBBClient.BoolExecution() {
        public boolean boolExecute() throws RemoteException {
          return client.setThermostatHoldMode(holdMode);
        }
      });
    } catch(OmniLinkBBClient.ExecutionException ex) {
      return false;
   
  }

  public boolean setSystemMode(final SystemMode systemMode) {
    try {
      return OmniLinkBBClient.execute(new OmniLinkBBClient.BoolExecution() {
        public boolean boolExecute() throws RemoteException {
          return client.setThermostatSystemMode(systemMode);
        }
      });
    } catch(OmniLinkBBClient.ExecutionException ex) {
      return false;
   
  }

  public void reset() {
    cachedThermostatStatus = null;
  }
 
  private ThermostatStatusResponse getThermostatStatusResponse() {
    if (cachedThermostatStatus == null) {
      try {
        cachedThermostatStatus = (ThermostatStatusResponse) OmniLinkBBClient.execute(new OmniLinkBBClient.Execution() {
          public Object execute() throws RemoteException {
            return client.getThermostatsStatus();
          }
        });
      } catch(OmniLinkBBClient.ExecutionException ex) {
        cachedThermostatStatus = new ThermostatStatusResponse();
     
    }
   
    return cachedThermostatStatus;
  }
}
TOP

Related Classes of net.homeip.mleclerc.omnilinkbbclient.model.ThermostatModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.