Beispiel #1
0
 public static DeviceType getStatus(Integer code) {
   for (DeviceType status : DeviceType.values()) {
     if (status.getCode() == code) {
       return status;
     }
   }
   throw new IllegalArgumentException("未能找到匹配的AutoInvestStatus:" + code);
 }
Beispiel #2
0
 public void getDevice() {
   String device = android.os.Build.DEVICE.toUpperCase();
   try {
     DeviceType type = Enum.valueOf(DeviceType.class, device);
     Constants.DEVICE = type.name();
     Constants.FORUM = type.getForumUrl();
   } catch (IllegalArgumentException e) {
     message = "Device not found/supported!";
     makeToast(message);
   }
 }
 @Override
 public void debug(Logger logger) {
   logger.fine("=== C_Message === ");
   logger.finer("\tRAW:        " + this.getPayload());
   logger.fine("DeviceType:    " + deviceType.toString());
   logger.fine("SerialNumber:  " + serialNumber);
   logger.fine("RFAddress:     " + rfAddress);
 }
  /**
   * create channels helper method
   *
   * @param device used to create key in channel
   */
  public static void createChannels(Device device) {
    List<DataPoint> datapoints = new ArrayList<DataPoint>();

    // get devicetype object matching the device
    Cursor cursor =
        homeMaticDatabase.query(
            DatabaseHelper.TABLE_DEVICETYPE,
            allColumnsDevicetype,
            DatabaseHelper.COLUMN_DEVICETYPE_HW + " = " + '"' + device.getType() + '"',
            null,
            null,
            null,
            null);
    cursor.moveToFirst();
    DeviceType deviceType = cursorToDeviceType(cursor);
    cursor.close();

    // get matching datapoints for the devicetype
    Cursor cursorDP =
        homeMaticDatabase.query(
            DatabaseHelper.TABLE_DP,
            allColumnsDP,
            DatabaseHelper.COLUMN_DP_CHANNEL_TYPE
                + " = "
                + '"'
                + deviceType.getChannel_type()
                + '"',
            null,
            null,
            null,
            null);
    cursorDP.moveToFirst();
    // get all datapoints
    while (!cursorDP.isAfterLast()) {
      DataPoint datapoint = cursorToDataPoint(cursorDP);
      datapoints.add(datapoint);
      cursorDP.moveToNext();
    }
    cursor.close();
    // create as many channels as deviceType.getCnt() with each having all datapoints
    for (int j = 0; j < deviceType.getCnt(); j++) {
      createChannel(datapoints, device, j);
    }
  }
  public C_Message(String raw) {
    super(raw);
    logger.fine(" *** C-Message ***");
    String[] tokens = this.getPayload().split(Message.DELIMETER);

    rfAddress = tokens[0];

    byte[] bytes = Base64.decodeBase64(tokens[1].getBytes());

    int[] data = new int[bytes.length];

    for (int i = 0; i < bytes.length; i++) {
      data[i] = bytes[i] & 0xFF;
    }

    length = data[0];
    if (length != data.length - 1) {
      logger.fine(
          "C_Message malformed: wrong data length. Expected bytes "
              + length
              + ", actual bytes "
              + (data.length - 1));
    }

    String rfAddress2 = Utils.toHex(data[1], data[2], data[3]);
    if (!rfAddress.toUpperCase().equals(rfAddress2.toUpperCase())) {
      logger.fine(
          "C_Message malformed: wrong RF address. Expected address "
              + rfAddress.toUpperCase()
              + ", actual address "
              + rfAddress2.toUpperCase());
    }

    deviceType = DeviceType.create(data[4]);

    serialNumber = getSerialNumber(bytes);
    if (deviceType == DeviceType.HeatingThermostatPlus
        || deviceType == DeviceType.HeatingThermostat
        || deviceType == DeviceType.WallMountedThermostat) parseHeatingThermostatData(bytes);
    if (deviceType == DeviceType.EcoSwitch || deviceType == DeviceType.ShutterContact)
      logger.finer(
          "Device " + rfAddress + " type " + deviceType.toString() + " Data:" + parseData(bytes));
  }
 public static DeviceType fromString(String deviceTypeString) {
   for (DeviceType deviceType : DeviceType.values()) {
     for (String synonym : deviceType.synonyms) {
       if (synonym.equalsIgnoreCase(deviceTypeString)) {
         return deviceType;
       }
     }
   }
   throw new RuntimeException("Unknown device type \"" + deviceTypeString + "\"");
 }
Beispiel #7
0
 private void instantiateFeatures(DeviceType dt) {
   for (Entry<String, String> fe : dt.getFeatures().entrySet()) {
     DeviceFeature f = DeviceFeature.s_makeDeviceFeature(fe.getValue());
     if (f == null) {
       logger.error("device type {} references unknown feature: {}", dt, fe.getValue());
     } else {
       addFeature(fe.getKey(), f);
     }
   }
   for (Entry<String, FeatureGroup> fe : dt.getFeatureGroups().entrySet()) {
     FeatureGroup fg = fe.getValue();
     DeviceFeature f = DeviceFeature.s_makeDeviceFeature(fg.getType());
     if (f == null) {
       logger.error("device type {} references unknown feature group: {}", dt, fg.getType());
     } else {
       addFeature(fe.getKey(), f);
     }
     connectFeatures(fe.getKey(), f, fg.getFeatures());
   }
 }
 public DeviceType unmarshall(JsonUnmarshallerContext context) throws Exception {
   AwsJsonReader reader = context.getReader();
   if (!reader.isContainer()) {
     reader.skipValue();
     return null;
   }
   DeviceType deviceType = new DeviceType();
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("DeviceKey")) {
       deviceType.setDeviceKey(StringJsonUnmarshaller.getInstance().unmarshall(context));
     } else if (name.equals("DeviceAttributes")) {
       deviceType.setDeviceAttributes(
           new ListUnmarshaller<AttributeType>(AttributeTypeJsonUnmarshaller.getInstance())
               .unmarshall(context));
     } else if (name.equals("DeviceCreateDate")) {
       deviceType.setDeviceCreateDate(DateJsonUnmarshaller.getInstance().unmarshall(context));
     } else if (name.equals("DeviceLastModifiedDate")) {
       deviceType.setDeviceLastModifiedDate(
           DateJsonUnmarshaller.getInstance().unmarshall(context));
     } else if (name.equals("DeviceLastAuthenticatedDate")) {
       deviceType.setDeviceLastAuthenticatedDate(
           DateJsonUnmarshaller.getInstance().unmarshall(context));
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return deviceType;
 }
Beispiel #9
0
 public void initFromPublicApiJsonObject(JSONObject jsonobject)
     throws JSONException
 {
     c(com.fitbit.d.a.a(jsonobject, "id"));
     a(com.fitbit.d.a.c(jsonobject, "lastSyncTime"));
     a(BatteryLevel.parse(com.fitbit.d.a.a(jsonobject, "battery")));
     a(DeviceType.parse(com.fitbit.d.a.a(jsonobject, "type")));
     String s1 = com.fitbit.d.a.a(jsonobject, "deviceVersion");
     a(DeviceVersion.parse(s1));
     e(s1);
     d(com.fitbit.d.a.a(jsonobject, "mac"));
     a(com.fitbit.d.a.a(jsonobject, "encrypted", true).booleanValue());
     setEntityStatus(com.fitbit.data.domain.Entity.EntityStatus.SYNCED);
 }
 /**
  * turns database cursor into object
  *
  * @param cursor cursor to database entry which should be returned into an object
  * @return object containing the database data
  */
 public static DeviceType cursorToDeviceType(Cursor cursor) {
   DeviceType deviceType = new DeviceType();
   deviceType.set_id(cursor.getLong(0));
   deviceType.setForgetIt(cursor.getString(1));
   deviceType.setHw(cursor.getString(2));
   deviceType.setCnt(cursor.getLong(3));
   deviceType.setChannel_type(cursor.getString(4));
   return deviceType;
 }
  /**
   * Creates the JSON string of the configuration as used in the Hyperion daemon configfile
   *
   * @return The JSON string of this DeviceConfig
   */
  public String toJsonString() {
    StringBuffer strBuf = new StringBuffer();

    strBuf.append("\t/// Device configuration contains the following fields: \n");
    strBuf.append(
        "\t/// * 'name'       : The user friendly name of the device (only used for display purposes)\n");
    strBuf.append(
        "\t/// * 'type'       : The type of the device or leds (known types for now are\n"
            + "\t/// "
            + DeviceType.listTypes()
            + ")\n");
    strBuf.append("\t/// * [device type specific configuration]\n");
    strBuf.append(
        "\t/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).\n");

    strBuf.append("\t\"device\" :\n");
    strBuf.append("\t{\n");

    strBuf.append("\t\t\"name\"       : \"").append(mName).append("\",\n");
    strBuf.append("\t\t\"type\"       : \"").append(mType.getTypeId()).append("\",\n");
    for (Object key : mDeviceProperties.keySet()) {
      Object value = mDeviceProperties.get(key);
      if (value instanceof String) {
        strBuf.append(String.format("\t\t\"%s\"     : \"%s\",\n", key, value));
      } else {
        strBuf.append(String.format("\t\t\"%s\"     : %s,\n", key, value.toString()));
      }
    }
    strBuf
        .append("\t\t\"colorOrder\" : \"")
        .append(mColorByteOrder.name().toLowerCase())
        .append("\"\n");

    strBuf.append("\t}");

    return strBuf.toString();
  }
  private void parseHeatingThermostatData(byte[] bytes) {
    try {

      int plusDataStart = 18;
      int programDataStart = 11;
      tempComfort = Float.toString(bytes[plusDataStart] / 2);
      tempEco = Float.toString(bytes[plusDataStart + 1] / 2);
      tempSetpointMax = Float.toString(bytes[plusDataStart + 2] / 2);
      tempSetpointMin = Float.toString(bytes[plusDataStart + 3] / 2);

      logger.fine("DeviceType:             " + deviceType.toString());
      logger.fine("RFAddress:              " + rfAddress);
      logger.fine("Temp Comfort:           " + tempComfort);
      logger.fine("TempEco:                " + tempEco);
      logger.fine("Temp Setpoint Max:      " + tempSetpointMax);
      logger.fine("Temp Setpoint Min:      " + tempSetpointMin);

      if (bytes.length < 211) {
        // Device is a WallMountedThermostat
        programDataStart = 4;
        logger.finer(
            "WallThermostat byte "
                + (bytes.length - 3)
                + ": "
                + Float.toString(bytes[bytes.length - 3] & 0xFF));
        logger.finer(
            "WallThermostat byte "
                + (bytes.length - 2)
                + ": "
                + Float.toString(bytes[bytes.length - 2] & 0xFF));
        logger.finer(
            "WallThermostat byte "
                + (bytes.length - 1)
                + ": "
                + Float.toString(bytes[bytes.length - 1] & 0xFF));
      } else {
        // Device is a HeatingThermostat(+)
        tempOffset = Double.toString((bytes[plusDataStart + 4] / 2) - 3.5);
        tempOpenWindow = Float.toString(bytes[plusDataStart + 5] / 2);
        durationOpenWindow = Float.toString(bytes[plusDataStart + 6]);
        boostDuration = Float.toString(bytes[plusDataStart + 7] & 0xFF >> 5);
        boostValve = Float.toString((bytes[plusDataStart + 7] & 0x1F) * 5);
        decalcification = Float.toString(bytes[plusDataStart + 8]);
        valveMaximum = Float.toString(bytes[plusDataStart + 9] & 0xFF * 100 / 255);
        valveOffset = Float.toString(bytes[plusDataStart + 10] & 0xFF * 100 / 255);
        logger.fine("Temp Offset:            " + tempOffset);
        logger.fine("Temp Open Window:       " + tempOpenWindow);
        logger.fine("Duration Open Window:   " + durationOpenWindow);
        logger.fine("Duration Boost:         " + boostDuration);
        logger.fine("Boost Valve Pos:        " + boostValve);
        logger.fine("Decalcification:        " + decalcification);
        logger.fine("ValveMaximum:           " + valveMaximum);
        logger.fine("ValveOffset:            " + valveOffset);
      }
      programData = "";
      int ln = 13 * 6; // first day = Sat
      String startTime = "00:00h";
      for (int char_idx = plusDataStart + programDataStart;
          char_idx < (plusDataStart + programDataStart + 26 * 7);
          char_idx++) {
        if (ln % 13 == 0) {
          programData += "\r\n Day " + Integer.toString((ln / 13) % 7) + ": ";
          startTime = "00:00h";
        }
        int progTime = (bytes[char_idx + 1] & 0xFF) * 5 + (bytes[char_idx] & 0x01) * 1280;
        int progMinutes = progTime % 60;
        int progHours = (progTime - progMinutes) / 60;
        String endTime =
            Integer.toString(progHours) + ":" + String.format("%02d", progMinutes) + "h";
        programData +=
            startTime + "-" + endTime + " " + Double.toString(bytes[char_idx] / 4) + "C  ";
        startTime = endTime;
        char_idx++;
        ln++;
      }
      logger.fine("ProgramData:          " + programData);

    } catch (Exception e) {
      logger.fine(e.getMessage());
      logger.fine(Utils.getStackTrace(e));
    }
    return;
  }
 protected Identity getIdentity() throws TimeoutException, NotConnectedException {
   if (identity == null) {
     identity = device.getIdentity();
   }
   return identity;
 }