Exemplo n.º 1
0
 /**
  * Updates a AudioZone's source text fields when a AudioSource changes
  *
  * @param as the audio source that has been updated
  */
 private void updateAudioZoneText(AudioSource as) {
   for (OmniLinkBindingProvider provider : providers) {
     for (String itemName : provider.getItemNames()) {
       OmniLinkBindingConfig config = provider.getOmniLinkBindingConfig(itemName);
       if (config != null) {
         switch (config.getObjectType()) {
           case AUDIOZONE_TEXT:
           case AUDIOZONE_TEXT_FIELD1:
           case AUDIOZONE_TEXT_FIELD2:
           case AUDIOZONE_TEXT_FIELD3:
             {
               AudioZone az = (AudioZone) config.getDevice();
               az.setAudioSource(audioSourceMap);
               if (az.getProperties().getSource() == as.getProperties().getNumber()) {
                 az.updateItem(provider.getItem(itemName), config, eventPublisher);
               }
             }
             break;
           default:
             break;
         }
       }
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Update any items linked to a Omni device.
  *
  * @param device
  */
 protected void updateItemsForDevice(OmnilinkDevice device) {
   for (OmniLinkBindingProvider provider : providers) {
     for (String itemName : provider.getItemNames()) {
       OmniLinkBindingConfig bindingConfig = provider.getOmniLinkBindingConfig(itemName);
       OmnilinkDevice itemDevice = bindingConfig.getDevice();
       Item item = provider.getItem(itemName);
       if (itemDevice != null && itemDevice == device) {
         device.updateItem(item, bindingConfig, eventPublisher);
       }
     }
   }
 }
Exemplo n.º 3
0
  /** @{inheritDoc */
  @Override
  protected void internalReceiveCommand(String itemName, Command command) {
    // the code being executed when a command was sent on the openHAB
    // event bus goes here. This method is only called if one of the
    // BindingProviders provide a binding for the given 'itemName'.
    logger.debug("internalReceiveCommand() is called!!! {} {} ", itemName, command);
    if (omniWorker != null && omniWorker.isConnected()) {
      for (OmniLinkBindingProvider provider : providers) {
        OmniLinkBindingConfig config = provider.getOmniLinkBindingConfig(itemName);
        Item item = provider.getItem(itemName);
        List<OmniLinkControllerCommand> commands =
            OmniLinkCommandMapper.getCommand(item, config, command);

        /*
         * send each command we get back
         */
        for (OmniLinkControllerCommand cmd : commands) {
          try {
            logger.debug(
                "Sending command {}/{}/{}",
                new Object[] {cmd.getCommand(), cmd.getParameter1(), cmd.getParameter2()});

            omniWorker
                .getOmniConnection()
                .controllerCommand(cmd.getCommand(), cmd.getParameter1(), cmd.getParameter2());

            // little hack to get audio updates faster.
            if (config.getObjectType() == OmniLinkItemType.AUDIOZONE_KEY) {
              audioUpdateLock.notifyAll();
            }

          } catch (IOException e) {
            logger.error("Could not send command", e);
          } catch (OmniNotConnectedException e) {
            logger.error("Could not send command", e);
          } catch (OmniInvalidResponseException e) {
            logger.error("Could not send command", e);
          } catch (OmniUnknownMessageTypeException e) {
            logger.error("Could not send command", e);
          }
        }
      }
    } else {
      logger.debug("Could not send message, connection not established {}", omniWorker == null);
    }

    // get the
  }
Exemplo n.º 4
0
    /**
     * This goes through a map of item names and updates their state's
     *
     * @throws IOException
     * @throws OmniNotConnectedException
     * @throws OmniInvalidResponseException
     * @throws OmniUnknownMessageTypeException
     */
    private void updateRefreshItems()
        throws IOException, OmniNotConnectedException, OmniInvalidResponseException,
            OmniUnknownMessageTypeException {

      if (refreshMap.size() == 0) return;

      Map<String, OmniLinkBindingConfig> itemMap =
          new HashMap<String, OmniLinkBindingConfig>(refreshMap);

      for (String itemName : itemMap.keySet()) {
        OmniLinkBindingConfig config = itemMap.get(itemName);
        refreshMap.remove(itemName);
        if (config != null) {
          Integer number = new Integer(config.getNumber());
          for (OmniLinkBindingProvider provider : providers) {
            switch (config.getObjectType()) {
              case UNIT:
                {
                  UnitProperties p = readUnitProperties(config.getNumber());
                  Unit unit = unitMap.get(number);
                  if (unit == null) {
                    unit = new Unit(p);
                    unitMap.put(number, unit);
                  }
                  config.setDevice(unit);
                  unit.setProperties(p);
                  unit.updateItem(provider.getItem(itemName), config, eventPublisher);
                }
                break;
              case THERMO_COOL_POINT:
              case THERMO_FAN_MODE:
              case THERMO_HEAT_POINT:
              case THERMO_HOLD_MODE:
              case THERMO_SYSTEM_MODE:
              case THERMO_TEMP:
                {
                  ThermostatProperties p = readThermoProperties(config.getNumber());
                  Thermostat thermo = thermostatMap.get(number);
                  if (thermo == null) {
                    thermo = new Thermostat(p, celius);
                    thermostatMap.put(number, thermo);
                  }
                  config.setDevice(thermo);
                  thermo.setProperties(p);
                  thermo.updateItem(provider.getItem(itemName), config, eventPublisher);
                }
                break;
              case AUDIOZONE_MUTE:
              case AUDIOZONE_POWER:
              case AUDIOZONE_SOURCE:
              case AUDIOZONE_KEY:
              case AUDIOZONE_TEXT:
              case AUDIOZONE_TEXT_FIELD1:
              case AUDIOZONE_TEXT_FIELD2:
              case AUDIOZONE_TEXT_FIELD3:
              case AUDIOZONE_VOLUME:
                {
                  AudioZoneProperties p = readAudioZoneProperties(config.getNumber());
                  AudioZone audioZone = audioZoneMap.get(number);
                  if (audioZone == null) {
                    audioZone = new AudioZone(p);
                    audioZone.setAudioSource(audioSourceMap);
                    audioZoneMap.put(number, audioZone);
                  }
                  config.setDevice(audioZone);
                  audioZone.setProperties(p);
                  audioZone.updateItem(provider.getItem(itemName), config, eventPublisher);
                }
                break;
              case AUDIOSOURCE_TEXT:
              case AUDIOSOURCE_TEXT_FIELD1:
              case AUDIOSOURCE_TEXT_FIELD2:
              case AUDIOSOURCE_TEXT_FIELD3:
                {
                  AudioSource as = audioSourceMap.get(number);
                  if (as != null) {
                    config.setDevice(as);
                    as.updateItem(provider.getItem(itemName), config, eventPublisher);
                  }
                }
                break;
              case AREA_ENTRY_TIMER:
              case AREA_EXIT_TIMER:
              case AREA_STATUS_ALARM:
              case AREA_STATUS_ENTRY_DELAY:
              case AREA_STATUS_EXIT_DELAY:
              case AREA_STATUS_MODE:
                {
                  AreaProperties p = readAreaProperties(config.getNumber());
                  Area area = areaMap.get(number);
                  if (area == null) {
                    area = new Area(p, omni);
                    areaMap.put(number, area);
                  }
                  config.setDevice(area);
                  area.setProperties(p);
                  area.updateItem(provider.getItem(itemName), config, eventPublisher);
                }
                break;
              case AUX_CURRENT:
              case AUX_HIGH:
              case AUX_LOW:
              case AUX_STATUS:
                {
                  AuxSensorProperties p = readAuxProperties(config.getNumber());
                  Auxiliary auxiliary = auxMap.get(number);
                  if (auxiliary == null) {
                    auxiliary = new Auxiliary(p, celius);
                    auxMap.put(number, auxiliary);
                  }
                  config.setDevice(auxiliary);
                  auxiliary.setProperties(p);
                  auxiliary.updateItem(provider.getItem(itemName), config, eventPublisher);
                }
                break;
              case ZONE_STATUS_ARMING:
              case ZONE_STATUS_CURRENT:
              case ZONE_STATUS_LATCHED:
              case ZONE_STATUS_ALL:
                {
                  ZoneProperties p = readZoneProperties(config.getNumber());
                  Zone zone = zoneMap.get(number);
                  if (zone == null) {
                    zone = new Zone(p);
                    zoneMap.put(number, zone);
                  }
                  config.setDevice(zone);
                  zone.setProperties(p);
                  zone.updateItem(provider.getItem(itemName), config, eventPublisher);
                }
                break;
              case BUTTON:
                {
                  ButtonProperties p = readButtonProperties(config.getNumber());
                  Button button = buttonMap.get(number);
                  if (button == null) {
                    button = new Button(p);
                    buttonMap.put(number, button);
                  }
                  config.setDevice(button);
                }
                break;
              default:
                break;
            }
          }
        }
      }
    }