Search in sources :

Example 1 with YamahaReceiverState

use of org.openhab.binding.yamahareceiver.internal.hardware.YamahaReceiverState in project openhab1-addons by openhab.

the class YamahaReceiverBinding method sendUpdates.

private void sendUpdates(YamahaReceiverProxy receiverProxy, String deviceUid) {
    // Get all item configurations belonging to this proxy
    Collection<YamahaReceiverBindingConfig> configs = getDeviceConfigs(deviceUid);
    try {
        for (Zone zone : Zone.values()) {
            // Poll the state from the device
            YamahaReceiverState state = receiverProxy.getState(zone);
            // Create state updates
            State powerUpdate = state.isPower() ? OnOffType.ON : OnOffType.OFF;
            State muteUpdate = state.isMute() ? OnOffType.ON : OnOffType.OFF;
            State inputUpdate = new StringType(state.getInput());
            State surroundUpdate = new StringType(state.getSurroundProgram());
            State updateVolumeDb = new DecimalType(state.getVolume());
            State updateVolumePercent = new PercentType((int) dbToPercent(state.getVolume()));
            // Send updates
            sendUpdate(configs, zone, BindingType.power, powerUpdate);
            sendUpdate(configs, zone, BindingType.mute, muteUpdate);
            sendUpdate(configs, zone, BindingType.input, inputUpdate);
            sendUpdate(configs, zone, BindingType.surroundProgram, surroundUpdate);
            sendUpdate(configs, zone, BindingType.volumePercent, updateVolumePercent);
            sendUpdate(configs, zone, BindingType.volumeDb, updateVolumeDb);
        }
    } catch (IOException e) {
        logger.warn("Cannot communicate with " + receiverProxy.getHost());
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) Zone(org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConfig.Zone) YamahaReceiverState(org.openhab.binding.yamahareceiver.internal.hardware.YamahaReceiverState) State(org.openhab.core.types.State) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) IOException(java.io.IOException) YamahaReceiverState(org.openhab.binding.yamahareceiver.internal.hardware.YamahaReceiverState)

Aggregations

IOException (java.io.IOException)1 Zone (org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConfig.Zone)1 YamahaReceiverState (org.openhab.binding.yamahareceiver.internal.hardware.YamahaReceiverState)1 DecimalType (org.openhab.core.library.types.DecimalType)1 PercentType (org.openhab.core.library.types.PercentType)1 StringType (org.openhab.core.library.types.StringType)1 State (org.openhab.core.types.State)1