示例#1
0
    /**
     * Populates all know audio sources which are used by known zones
     *
     * @throws IOException
     * @throws OmniNotConnectedException
     * @throws OmniInvalidResponseException
     * @throws OmniUnknownMessageTypeException
     */
    private void readAllAudioSources()
        throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
            OmniUnknownMessageTypeException {
      int objnum = 0;
      Message m;
      while ((m =
                  c.reqObjectProperties(
                      Message.OBJ_TYPE_AUDIO_SOURCE,
                      objnum,
                      1,
                      ObjectProperties.FILTER_1_NAMED,
                      ObjectProperties.FILTER_2_NONE,
                      ObjectProperties.FILTER_3_NONE))
              .getMessageType()
          == Message.MESG_TYPE_OBJ_PROP) {
        // logger.info(m.toString());
        AudioSourceProperties o = ((AudioSourceProperties) m);
        objnum = ((ObjectProperties) m).getNumber();

        Integer number = new Integer(o.getNumber());
        AudioSource as = audioSourceMap.get(number);
        if (as == null) {
          as = new AudioSource(o);
          audioSourceMap.put(number, as);
        }
        audioSourceMap.put(new Integer(o.getNumber()), as);
      }
    }
示例#2
0
 /**
  * Iterate through the system units (lights)
  *
  * @param number of the unti
  * @return UnitProperties of unit, null if not found
  * @throws IOException
  * @throws OmniNotConnectedException
  * @throws OmniInvalidResponseException
  * @throws OmniUnknownMessageTypeException
  */
 private UnitProperties readUnitProperties(int number)
     throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
         OmniUnknownMessageTypeException {
   Message m =
       c.reqObjectProperties(
           Message.OBJ_TYPE_UNIT,
           number,
           0,
           ObjectProperties.FILTER_1_NAMED,
           ObjectProperties.FILTER_2_AREA_ALL,
           ObjectProperties.FILTER_3_ANY_LOAD);
   if (m.getMessageType() == Message.MESG_TYPE_OBJ_PROP) {
     return ((UnitProperties) m);
   }
   return null;
 }
示例#3
0
    /**
     * Read the properties of a button
     *
     * @param number of button
     * @return ButtonProperties of button, or null if not found
     * @throws IOException
     * @throws OmniNotConnectedException
     * @throws OmniInvalidResponseException
     * @throws OmniUnknownMessageTypeException
     */
    private ButtonProperties readButtonProperties(int number)
        throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
            OmniUnknownMessageTypeException {

      Message m =
          c.reqObjectProperties(
              Message.OBJ_TYPE_BUTTON,
              number,
              0,
              ObjectProperties.FILTER_1_NAMED,
              ObjectProperties.FILTER_2_NONE,
              ObjectProperties.FILTER_3_NONE);
      if (m.getMessageType() == Message.MESG_TYPE_OBJ_PROP) {
        return ((ButtonProperties) m);
      }
      return null;
    }
示例#4
0
    /**
     * Update audio zone text fields, this is one of the few things we need to poll for
     *
     * @throws IOException
     * @throws OmniNotConnectedException
     * @throws OmniInvalidResponseException
     * @throws OmniUnknownMessageTypeException
     */
    private void updateAudioSourceTexts()
        throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
            OmniUnknownMessageTypeException {
      Iterator<Integer> it = audioSourceMap.keySet().iterator();
      while (it.hasNext()) {
        Integer source = it.next();
        int pos = 0;
        Message m;
        boolean updated = false;
        Vector<String> text = new Vector<String>();
        while ((m = c.reqAudioSourceStatus(source.intValue(), pos)).getMessageType()
            == Message.MESG_TYPE_AUDIO_SOURCE_STATUS) {
          AudioSourceStatus a = (AudioSourceStatus) m;
          text.add(a.getSourceData());
          pos = a.getPosition();
        }

        AudioSource as = audioSourceMap.get(source);

        String text2[] = as.getAudioText();

        if (text.size() == text2.length) {
          for (int i = 0; i < text.size(); i++) {
            if (!text2[i].equals(text.get(i))) {
              updated = true;
            }
          }
        } else {
          updated = true;
        }

        if (updated) {
          as.setAudioText(text.toArray(new String[0]));
          updateAudioZoneText(as);
        }
      }
    }
示例#5
0
  /**
   * Generates button items
   *
   * @throws IOException
   * @throws OmniNotConnectedException
   * @throws OmniInvalidResponseException
   * @throws OmniUnknownMessageTypeException
   */
  private void generateButtons()
      throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
          OmniUnknownMessageTypeException {

    String groupString = "Group\t%s\t\"%s\"\t(%s)\n";
    String itemString = "%s\t%s\t\"%s\"\t(%s)\t{omnilink=\"%s:%d\",autoupdate=\"false\"}\n";
    String groupName = "Buttons";
    groups.append(String.format(groupString, groupName, "Buttons", "All"));

    int objnum = 0;
    Message m;

    while ((m =
                c.reqObjectProperties(
                    Message.OBJ_TYPE_BUTTON,
                    objnum,
                    1,
                    ObjectProperties.FILTER_1_NAMED,
                    ObjectProperties.FILTER_2_AREA_ALL,
                    ObjectProperties.FILTER_3_NONE))
            .getMessageType()
        == Message.MESG_TYPE_OBJ_PROP) {
      ButtonProperties o = ((ButtonProperties) m);
      objnum = o.getNumber();

      // String group = addUniqueGroup(groupName + "_" + cleanString(o.getName()));

      // groups.append(String.format(groupString,group,o.getName(),groupName));
      String name = groupName + "_" + cleanString(o.getName());

      buttons.add(new SiteItem(name, o.getName(), o.getName()));

      items.append(
          String.format(itemString, "String", name, o.getName(), groupName, "button", objnum));
    }
  }
示例#6
0
  /**
   * Generates a crude sitemap from our generated items.
   *
   * @throws IOException
   * @throws OmniNotConnectedException
   * @throws OmniInvalidResponseException
   * @throws OmniUnknownMessageTypeException
   */
  private void generateSiteMap()
      throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
          OmniUnknownMessageTypeException {
    StringBuilder output = new StringBuilder();
    // begin sitemap
    output.append("sitemap home label=\"Main Menu\"{\n");
    output.append("Frame {\n\n");
    // begin lights
    output.append("Text label=\"Lights\"icon=\"" + IMG_LIGHT + "\" {\n");
    output.append("Frame {\n");

    for (String room : rooms.keySet()) {
      LinkedList<SiteItem> units = rooms.get(room);
      SiteItem fLight = units.removeFirst();

      output.append(
          String.format(
              "Text label=\"%s [%%s]\" item=%s_String icon=\"%s\" valuecolor=[==Off=\"white\",!=Off=\"green\"]{\n",
              fLight.getObjName(), fLight.getName(), IMG_LIGHT));
      output.append(
          String.format(
              "Frame item=%s_Switch label=\"%s [%%s%%%%]\"{\n",
              fLight.getName(), fLight.getObjName()));
      output.append(
          String.format(
              "Switch item=%s_Switch label=\"Power\" icon=\"\" mappings=[\"0\"=Off, \"100\"=On]\n",
              fLight.getName()));
      output.append(
          String.format("Slider item=%s_Switch label=\"Dimmer\" icon=\"\"\n", fLight.getName()));
      output.append(
          String.format(
              "Switch item=%s_String label=\"Scene\" icon=\"\" mappings=[\"Scene A\"=A, \"Scene B\"=B, \"Scene C\"=C, \"Scene D\"=D]\n",
              fLight.getName()));

      output.append("}\nFrame label=\"All Lights\"{\n");
      for (SiteItem l : units) {
        output.append(String.format("Slider item=%s_Switch switchSupport\n", l.getName()));
      }
      output.append("}\n}\n");
    }
    if (lights.size() > 0) {
      output.append("Text label=\"Other\" {\n");
      output.append("Frame{\n");
      for (SiteItem l : lights) {
        output.append(String.format("Slider item=%s_Switch switchSupport\n", l.getName()));
      }
      output.append("}\n}\n");
    }
    // end lights
    output.append("}\n}\n");

    // begin thermos
    if (thermos.size() > 0) {
      output.append("Text label=\"Thermostats\"icon=\"" + IMG_THERMOS + "\" {\n");
      output.append("Frame {\n");

      for (SiteItem thermo : thermos) {
        output.append(
            String.format(
                "Text label=\"%s  [%%d°F]\" item=%s_Temp icon=\"%s\" {\n",
                thermo.getObjName(), thermo.getName(), IMG_THERMOS));
        output.append(
            String.format(
                "Frame item=%s_Temp label=\"%s [%%d°F]\"{\n",
                thermo.getName(), thermo.getObjName()));

        output.append(
            String.format(
                "Setpoint item=%s_CoolPoint minValue=32 maxValue=100 step=1\n icon=\"%s-cool\"",
                thermo.getName(), IMG_THERMOS));
        output.append(
            String.format(
                "Setpoint item=%s_HeatPoint minValue=32 maxValue=100 step=1\n icon=\"%s-heat\"",
                thermo.getName(), IMG_THERMOS));
        output.append(
            String.format(
                "Switch item=%s_System label=\"Mode\" icon=\"%s\" mappings=[\"0\"=Off, \"1\"=Heat, \"2\"=Cool,\"3\"=Auto,\"4\"=Emer]\n",
                thermo.getName(), IMG_THERMOS));
        output.append(
            String.format(
                "Switch item=%s_Fan label=\"Fan\" mappings=[\"0\"=Auto, \"1\"=On]\n",
                thermo.getName()));
        output.append(
            String.format(
                "Switch item=%s_Hold label=\"Hold\" mappings=[\"0\"=Off, \"1\"=On]\n",
                thermo.getName()));
        output.append("}\n}\n");
      }
      // end thermos
      output.append("}\n}\n");
    }
    // begin audioZones
    if (audioZones.size() > 0) {
      output.append("Text label=\"Audio\" icon=\"" + IMG_AUDIO + "\"{\n");
      output.append("Frame {\n");
      for (SiteItem audio : audioZones) {
        output.append(
            String.format(
                "Text label=\"%s  [%%s]\" item=%s_Power icon=\"%s\" valuecolor=[==OFF=\"white\",!=OFF=\"green\"]{\n",
                audio.getObjName(), audio.getName(), IMG_AUDIO));
        output.append(
            String.format(
                "Frame item=%s_Volume label=\"%s  [%%s%%%%]\"{\n",
                audio.getName(), audio.getObjName()));
        output.append(
            String.format("Switch item=%s_Power icon=\"\" label=\"Power\"\n", audio.getName()));
        output.append(
            String.format("Switch item=%s_Mute  icon=\"\" label=\"Mute\"\n", audio.getName()));
        output.append(
            String.format(
                "Switch item=%s_Source icon=\"\" label=\"Source\" mappings=[\"1\"=XM, \"2\"=iPod, \"3\"=Tivo,\"4\"=Sqz1,\"5\"=Air,\"6\"=Sqz2]\n",
                audio.getName()));
        output.append(
            String.format("Slider item=%s_Volume icon=\"\" label=\"Volume\"\n", audio.getName()));

        int[] features = c.reqSystemFeatures().getFeatures();
        String[] audioCmd = null;
        for (int i = 0; i < features.length; i++) {
          switch (features[i]) {
            case 1: // Nuvo Concerto
            case 2: // Nuvo Essentials/Simplese
              audioCmd = AUDIOCMD_NUVO;
              break;
            case 3: // Nuvo Grand
              audioCmd = AUDIOCMD_NUVOGRAND;
              break;
            case 4: // Russound
              audioCmd = AUDIOCMD_RUSSOUND;
              break;
            case 5: // HAI Hi-Fi
              audioCmd = AUDIOCMD_HAIHIFI;
              break;
            case 6: // XANTECH
              audioCmd = AUDIOCMD_XANTECH;
              ;
              break;
            case 7: // SpeakerCraft
              audioCmd = AUDIOCMD_SPEAKEERCRAFT;
              break;
            default:
              break;
          }
          if (audioCmd != null) break;
        }

        // we should do something smarter here

        // for russound starting at index 5 + 1
        // "Play", "Stop", "Pause", "Minus" Plus", "Previous", "Next ",
        if (audioCmd.length > 12)
          output.append(
              String.format(
                  "Switch item=%s_Key label=\"\" mappings=[\"6\"=\">\", \"7\"=\"[ ]\", \"8\"=\"||\",\"9\"=\"-\",\"10\"=\"+\",\"11\"=\"<<\",\"12\"=\">>\"]\n",
                  audio.getName()));

        output.append(String.format("Text item=%s_Text label=\"[%%s]\"\n", audio.getName()));
        output.append(String.format("Text item=%s_Field1 label=\"[%%s]\"\n", audio.getName()));
        output.append(String.format("Text item=%s_Field2 label=\"[%%s]\"\n", audio.getName()));
        output.append(String.format("Text item=%s_Field3 label=\"[%%s]\"\n", audio.getName()));
        output.append("}\n}\n");
      }

      // end audioZones
      output.append("}\n}\n");

      // begin zones
      if (zones.size() > 0) {

        output.append("Text label=\"Zones\" icon=\"" + IMG_SECURITY + "\" {\n");
        output.append("Frame {\n");
        for (SiteItem zone : zones) {
          output.append(
              String.format(
                  "Text label=\"%s\" item=%s_Current{\n", zone.getObjName(), zone.getName()));
          output.append(String.format("Frame label=\"%s\"{\n", zone.getObjName()));
          output.append(
              String.format(
                  "Switch item=%s_Arming label=\"\" icon=\"\" mappings=[\"bypass\"=Bypass, \"restore\"=Restore]\n",
                  zone.getName()));
          output.append(
              String.format(
                  "Text item=%s_Current icon=\"\" label=\"Current: [%%s]\"\n",
                  zone.getName(), zone.getObjName()));
          output.append(
              String.format(
                  "Text item=%s_Latched label=\"Latched: [%%s]\"",
                  zone.getName(), zone.getObjName()));
          output.append(
              String.format(
                  "Text item=%s_Arming label=\"Arming: [%%s]\"\n",
                  zone.getName(), zone.getObjName()));
          output.append("}\n}\n");
        }
        // end zones
        output.append("}\n}\n");
      }

      // begin buttons
      if (buttons.size() > 0) {
        output.append("Text label=\"Buttons\" icon=\"" + IMG_BUTTON + "\"{\n");
        output.append("Frame {\n");

        for (SiteItem button : buttons) {
          output.append(
              String.format(
                  "Switch item=%s label=\"%s\" icon=\"\" mappings=[\"push\"=\"Push\"]\n",
                  button.getName(), button.getObjName()));
        }
        // end buttons
        output.append("}\n}\n");
      }
    }
    // end sitemap
    output.append("\n\n}\n}\n");
    System.out.println(output.toString());
  }
示例#7
0
  /**
   * Generates are items
   *
   * @throws IOException
   * @throws OmniNotConnectedException
   * @throws OmniInvalidResponseException
   * @throws OmniUnknownMessageTypeException
   */
  private void generateAreas()
      throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
          OmniUnknownMessageTypeException {

    String groupString = "Group\t%s\t\"%s\"\t(%s)\n";
    String itemString = "%s\t%s\t\"%s\"\t(%s)\t{omnilink=\"%s:%d\"}\n";
    String groupName = "Areas";
    groups.append(String.format(groupString, groupName, "Areas", "All"));

    int objnum = 0;
    Message m;

    while ((m =
                c.reqObjectProperties(
                    Message.OBJ_TYPE_AREA,
                    objnum,
                    1,
                    ObjectProperties.FILTER_1_NAMED,
                    ObjectProperties.FILTER_2_NONE,
                    ObjectProperties.FILTER_3_NONE))
            .getMessageType()
        == Message.MESG_TYPE_OBJ_PROP) {
      AreaProperties o = ((AreaProperties) m);
      objnum = o.getNumber();

      String group = addUniqueGroup(groupName + "_" + cleanString(o.getName()));

      groups.append(String.format(groupString, group, o.getName(), groupName));
      // String name = group + "_" + cleanString(o.getName());

      areas.add(new SiteItem(group, o.getName(), o.getName()));

      items.append(
          String.format(
              itemString,
              "Number",
              group + "_ExitDelay",
              "Exit Delay: [%d]",
              group,
              "area_status_exit_delay",
              objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_EntryDelay",
              "Entry Delay: [%d]",
              group,
              "area_status_entry_delay",
              objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_ExitTimer",
              "Exit Timer: [%d]",
              group,
              "area_status_exit_timer",
              objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_EntryTimer",
              "Entry Timer: [%d]",
              group,
              "area_status_entry_timer",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Mode",
              "Mode: [%s]",
              group,
              "area_status_mode",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Alarm",
              "Alarm: [%s]",
              group,
              "area_status_alarm",
              objnum));
    }
  }
示例#8
0
  /**
   * Generates zone items
   *
   * @throws IOException
   * @throws OmniNotConnectedException
   * @throws OmniInvalidResponseException
   * @throws OmniUnknownMessageTypeException
   */
  private void generateZones()
      throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
          OmniUnknownMessageTypeException {

    String groupString = "Group\t%s\t\"%s\"\t(%s)\n";
    String itemString = "%s\t%s\t\"%s\"\t(%s)\t{omnilink=\"%s:%d\"}\n";
    String groupName = "Zones";
    groups.append(String.format(groupString, groupName, "Zones", "All"));

    int objnum = 0;
    Message m;

    while ((m =
                c.reqObjectProperties(
                    Message.OBJ_TYPE_ZONE,
                    objnum,
                    1,
                    ObjectProperties.FILTER_1_NAMED,
                    ObjectProperties.FILTER_2_AREA_ALL,
                    ObjectProperties.FILTER_3_ANY_LOAD))
            .getMessageType()
        == Message.MESG_TYPE_OBJ_PROP) {
      ZoneProperties o = ((ZoneProperties) m);
      objnum = o.getNumber();

      String group = addUniqueGroup(groupName + "_" + cleanString(o.getName()));

      groups.append(String.format(groupString, group, o.getName(), groupName));
      // String name = group + "_" + cleanString(o.getName());

      zones.add(new SiteItem(group, o.getName(), o.getName()));

      items.append(
          String.format(
              itemString,
              "Contact",
              group + "_Current",
              "Current: [%s]",
              group,
              "zone_status_current",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Latched",
              "Latched [%s]",
              group,
              "zone_status_latched",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Arming",
              "Arming [%s]",
              group,
              "zone_status_arming",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_All",
              "Status  [%s]",
              group,
              "zone_status_all",
              objnum));
    }
  }
示例#9
0
  /**
   * Generates audio source items
   *
   * @throws IOException
   * @throws OmniNotConnectedException
   * @throws OmniInvalidResponseException
   * @throws OmniUnknownMessageTypeException
   */
  private void generateAudioSource()
      throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
          OmniUnknownMessageTypeException {

    String groupString = "Group\t%s\t\"%s\"\t(%s)\n";
    String itemString = "%s\t%s\t\"%s\"\t(%s)\t{omnilink=\"%s:%d\"}\n";
    String groupName = "AudioSources";
    groups.append(String.format(groupString, groupName, "Audio Sources", "All"));
    int objnum = 0;
    Message m;

    while ((m =
                c.reqObjectProperties(
                    Message.OBJ_TYPE_AUDIO_SOURCE,
                    objnum,
                    1,
                    ObjectProperties.FILTER_1_NAMED,
                    ObjectProperties.FILTER_2_NONE,
                    ObjectProperties.FILTER_3_NONE))
            .getMessageType()
        == Message.MESG_TYPE_OBJ_PROP) {
      AudioSourceProperties o = ((AudioSourceProperties) m);
      objnum = o.getNumber();

      String group = addUniqueGroup(groupName + "_" + cleanString(o.getName()));

      groups.append(String.format(groupString, group, o.getName(), "OmniAudioSources"));
      // String name = group + "_" + cleanString(o.getName());

      audioSources.add(new SiteItem(group, o.getName(), o.getName()));

      items.append(
          String.format(
              itemString,
              "String",
              group + "_Text",
              "Now Playeing: [%s]",
              group,
              "audiosource_text",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Field1",
              "Field 1 [%s]",
              group,
              "audiosource_field1",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Field2",
              "Field 2 [%s]",
              group,
              "audiosource_field2",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Field3",
              "Field 3 [%s]",
              group,
              "audiosource_field3",
              objnum));
    }
  }
示例#10
0
  /**
   * Generates audio zone items
   *
   * @throws IOException
   * @throws OmniNotConnectedException
   * @throws OmniInvalidResponseException
   * @throws OmniUnknownMessageTypeException
   */
  private void generateAudioZones()
      throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
          OmniUnknownMessageTypeException {

    String groupString = "Group\t%s\t\"%s\"\t(%s)\n";
    String itemString = "%s\t%s\t\"%s\"\t(%s)\t{omnilink=\"%s:%d\"}\n";
    String itemStringKey = "%s\t%s\t\"%s\"\t(%s)\t{omnilink=\"%s:%d\",autoupdate=\"false\"}\n";
    String groupName = "AudioZones";
    groups.append(String.format(groupString, groupName, "Audio Zones", "All"));
    int objnum = 0;
    Message m;

    while ((m =
                c.reqObjectProperties(
                    Message.OBJ_TYPE_AUDIO_ZONE,
                    objnum,
                    1,
                    ObjectProperties.FILTER_1_NAMED,
                    ObjectProperties.FILTER_2_NONE,
                    ObjectProperties.FILTER_3_NONE))
            .getMessageType()
        == Message.MESG_TYPE_OBJ_PROP) {
      AudioZoneProperties o = ((AudioZoneProperties) m);
      objnum = o.getNumber();

      String group = addUniqueGroup(groupName + "_" + cleanString(o.getName()));

      groups.append(String.format(groupString, group, o.getName(), groupName));
      // String name = group + "_" + cleanString(o.getName());

      audioZones.add(new SiteItem(group, o.getName(), o.getName()));

      items.append(
          String.format(
              itemString, "Switch", group + "_Power", "Power", group, "audiozone_power", objnum));
      items.append(
          String.format(
              itemString, "Switch", group + "_Mute", "Mute", group, "audiozone_mute", objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_Source",
              "Source: [%d]",
              group,
              "audiozone_source",
              objnum));
      items.append(
          String.format(
              itemString,
              "Dimmer",
              group + "_Volume",
              "Voulme: [%d %%]",
              group,
              "audiozone_volume",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Text",
              "Now Playing: [%s]",
              group,
              "audiozone_text",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Field1",
              "Field 1 [%s]",
              group,
              "audiozone_field1",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Field2",
              "Field 2 [%s]",
              group,
              "audiozone_field2",
              objnum));
      items.append(
          String.format(
              itemString,
              "String",
              group + "_Field3",
              "Field 3 [%s]",
              group,
              "audiozone_field3",
              objnum));
      items.append(
          String.format(
              itemStringKey, "Number", group + "_Key", "Key [%d]", group, "audiozone_key", objnum));
    }
  }
示例#11
0
  /**
   * Generates thermostat items
   *
   * @throws IOException
   * @throws OmniNotConnectedException
   * @throws OmniInvalidResponseException
   * @throws OmniUnknownMessageTypeException
   */
  private void generateThermos()
      throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
          OmniUnknownMessageTypeException {

    String groupString = "Group\t%s\t\"%s\"\t(%s)\n";
    String itemString = "%s\t%s\t\"%s\"\t(%s)\t{omnilink=\"%s:%d\"}\n";
    String groupName = "Thermostats";
    groups.append(String.format(groupString, groupName, "Thermostats", "All"));
    int objnum = 0;
    Message m;

    while ((m =
                c.reqObjectProperties(
                    Message.OBJ_TYPE_THERMO,
                    objnum,
                    1,
                    ObjectProperties.FILTER_1_NAMED,
                    ObjectProperties.FILTER_2_AREA_ALL,
                    ObjectProperties.FILTER_3_ANY_LOAD))
            .getMessageType()
        == Message.MESG_TYPE_OBJ_PROP) {
      ThermostatProperties o = ((ThermostatProperties) m);
      objnum = o.getNumber();
      String objName = cleanString(o.getName());
      String group = addUniqueGroup(groupName + "_" + objName);

      groups.append(String.format(groupString, group, o.getName(), "OmniThermostat"));

      thermos.add(new SiteItem(group, o.getName(), o.getName()));

      items.append(
          String.format(
              itemString,
              "Number",
              group + "_Temp",
              "Temperature [%d °F]",
              group,
              "thermo_temp",
              objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_CoolPoint",
              "Cool Point [%d°F]",
              group,
              "thermo_cool_point",
              objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_HeatPoint",
              "Heat Point [%d°F]",
              group,
              "thermo_heat_point",
              objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_System",
              "System Mode [%d]",
              group,
              "thermo_system_mode",
              objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_Fan",
              "System Fan [%d]",
              group,
              "thermo_fan_mode",
              objnum));
      items.append(
          String.format(
              itemString,
              "Number",
              group + "_Hold",
              "System Hold [%d]",
              group,
              "thermo_hold_mode",
              objnum));
    }
  }
示例#12
0
  /**
   * This is by far the most complex method as units have the ability to be sub-grouped into rooms.
   * If units are in a room then they will be added to their own group which is a member of the
   * Lights group.
   *
   * @throws IOException
   * @throws OmniNotConnectedException
   * @throws OmniInvalidResponseException
   * @throws OmniUnknownMessageTypeException
   */
  private void generateUnits()
      throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
          OmniUnknownMessageTypeException {

    // Group	Lights_GreatRoom	"Great Room"	(Lights)
    String groupString = "Group\t%s\t\"%s\"\t(%s)\n";

    // Dimmer	Lights_GreatRoom_MainLights_Switch	"Main Lights [%d%%]"	(Lights_GreatRoom)
    //	{omnilink="unit:10"}
    String itemString = "%s\t%s\t\"%s\"\t(%s)\t{omnilink=\"unit:%d\"}\n";

    String groupName = "Lights";

    // Group	Lights	"Lights"	(All)
    groups.append(String.format(groupString, groupName, "Lights", "All"));

    int objnum = 0;
    Message m;
    int currentRoom = 0;
    String currentRoomName = null;

    while ((m =
                c.reqObjectProperties(
                    Message.OBJ_TYPE_UNIT,
                    objnum,
                    1,
                    ObjectProperties.FILTER_1_NAMED,
                    ObjectProperties.FILTER_2_AREA_ALL,
                    ObjectProperties.FILTER_3_ANY_LOAD))
            .getMessageType()
        == Message.MESG_TYPE_OBJ_PROP) {
      UnitProperties o = ((UnitProperties) m);
      objnum = o.getNumber();

      boolean isInRoom = false;
      boolean isRoomController = false;
      if (o.getUnitType() == UnitProperties.UNIT_TYPE_HLC_ROOM
          || o.getObjectType() == UnitProperties.UNIT_TYPE_VIZIARF_ROOM) {
        currentRoom = objnum;

        // Lights_LivingRoom
        currentRoomName = cleanString(groupName + "_" + o.getName());

        // Make Sure we don't already have a group called this
        currentRoomName = addUniqueGroup(currentRoomName);

        groups.append(String.format(groupString, currentRoomName, o.getName(), groupName));
        rooms.put(currentRoomName, new LinkedList<SiteItem>());
        isInRoom = true;
        isRoomController = true;
      } else if (objnum < currentRoom + 8) {
        isInRoom = true;
      }

      // clean the name to remove things like spaces
      String objName = cleanString(o.getName());

      String group = isInRoom ? currentRoomName : groupName;

      // name will be the room name for the first device and roomName_deviceName for sub devices
      String name = isRoomController ? objName : group + "_" + objName;

      // the label does not have to be cleaned, so set it from the object
      String label = o.getName() + " [%d%%]";

      SiteItem light = new SiteItem(name, o.getName(), label);

      items.append(String.format(itemString, "Dimmer", name + "_Switch", label, group, objnum));

      if (isRoomController)
        items.append(
            String.format(
                itemString, "String", name + "_String", o.getName() + " [%s]", group, objnum));

      if (isInRoom) rooms.get(currentRoomName).add(light);
      else lights.add(light);
    }
  }
示例#13
0
    /** Main processing loop */
    @Override
    public void run() {
      running = true;
      logger.debug("OmniConnectionThread running");
      while (running) {
        connected = false;

        /*
         * Connect to the system
         */

        logger.debug("OmniConnectionThread trying to connect");

        try {
          c = new Connection(host, port, key);
          connected = true;
          logger.debug("OmniConnectionThread connected");
        } catch (Exception e) {
          logger.error("Could not connect", e);
        }

        /*
         * If we fail to connect sleep a bit before trying again
         */
        if (!connected) {
          try {
            Thread.currentThread();
            Thread.sleep(10 * 1000);
          } catch (InterruptedException ignored) {
          }

        } else {

          /*
           * If we get disconnected then do nothing
           */
          c.addDisconnectListener(
              new DisconnectListener() {
                @Override
                public void notConnectedEvent(Exception e) {
                  logger.error("OmniConnectionThread was disconnected, will try again", e);
                  connected = false;
                }
              });

          /*
           * Real time device changes get processed here
           */
          c.addNotificationListener(listener);

          /*
           * Load everything and main audio source text loop
           */
          try {
            SystemStatus sysstatus = c.reqSystemStatus();
            logger.info("System: " + sysstatus.toString());

            omni = c.reqSystemInformation().getModel() < 36;

            /*
             * We need to explicitly tell the controller to send us
             * real time notifications
             */
            c.enableNotifications();

            if (generateItems) {
              OmnilinkItemGenerator gen = new OmnilinkItemGenerator(c);
              logger.info(gen.generateItemsAndGroups());
            }

            // update known items with state
            populateRefreshMapFromAllProviders();

            // load audio sources, we won't get updates on these
            readAllAudioSources();

            /*
             * if we get disconnected then refresh any devices that
             * we have to keep them up to date.
             */

            while (running && c.connected()) {
              updateRefreshItems();
              /*
               * Audio source text is not pushed in real time, so
               * we poll for it
               */
              updateAudioSourceTexts();
              try {
                synchronized (audioUpdateLock) {
                  audioUpdateLock.wait(5000);
                }
              } catch (InterruptedException ignored) {
              }
            }
          } catch (IOException ex) {
            logger.error("Could not connect to system", ex);
          } catch (OmniNotConnectedException ex) {
            logger.error("Could not connect to system", ex.getNotConnectedReason());
          } catch (OmniInvalidResponseException ex) {
            logger.error("Could not connect to system", ex);
          } catch (OmniUnknownMessageTypeException ex) {
            logger.error("Could not connect to system", ex);
            // is this needed? I just added this without looking at
            // the code for 2 years
          } catch (Exception ex) {
            logger.error("Could not connect to system", ex);
          } finally {
            c.disconnect();
            c = null;
          }
        }
      }
    }