Search in sources :

Example 6 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class ZonePlayerHandler method onValueReceived.

@Override
public void onValueReceived(String variable, String value, String service) {
    if (getThing().getStatus() == ThingStatus.ONLINE) {
        logger.trace("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() });
        String oldValue = this.stateMap.get(variable);
        if (shouldIgnoreVariableUpdate(variable, value, oldValue)) {
            return;
        }
        this.stateMap.put(variable, value);
        // pre-process some variables, eg XML processing
        if (service.equals("AVTransport") && variable.equals("LastChange")) {
            Map<String, String> parsedValues = SonosXMLParser.getAVTransportFromXML(value);
            for (String parsedValue : parsedValues.keySet()) {
                // to not break the notification mechanism
                if (!parsedValue.equals("TransportState")) {
                    onValueReceived(parsedValue, parsedValues.get(parsedValue), "AVTransport");
                }
                // for a compatibility with the result of the action GetMediaInfo
                if (parsedValue.equals("AVTransportURI")) {
                    onValueReceived("CurrentURI", parsedValues.get(parsedValue), service);
                } else if (parsedValue.equals("AVTransportURIMetaData")) {
                    onValueReceived("CurrentURIMetaData", parsedValues.get(parsedValue), service);
                }
            }
            updateMediaInformation();
            if (parsedValues.get("TransportState") != null) {
                onValueReceived("TransportState", parsedValues.get("TransportState"), "AVTransport");
            }
        }
        if (service.equals("RenderingControl") && variable.equals("LastChange")) {
            Map<String, String> parsedValues = SonosXMLParser.getRenderingControlFromXML(value);
            for (String parsedValue : parsedValues.keySet()) {
                onValueReceived(parsedValue, parsedValues.get(parsedValue), "RenderingControl");
            }
        }
        // update the appropriate channel
        switch(variable) {
            case "TransportState":
                updateChannel(STATE);
                updateChannel(CONTROL);
                updateChannel(STOP);
                dispatchOnAllGroupMembers(variable, value, service);
                break;
            case "CurrentPlayMode":
                updateChannel(SHUFFLE);
                updateChannel(REPEAT);
                dispatchOnAllGroupMembers(variable, value, service);
                break;
            case "CurrentLEDState":
                updateChannel(LED);
                break;
            case "ZoneName":
                updateState(ZONENAME, (stateMap.get("ZoneName") != null) ? new StringType(stateMap.get("ZoneName")) : UnDefType.UNDEF);
                break;
            case "CurrentZoneName":
                updateChannel(ZONENAME);
                break;
            case "ZoneGroupState":
                updateChannel(COORDINATOR);
                // Update coordinator after a change is made to the grouping of Sonos players
                updateGroupCoordinator();
                updateMediaInformation();
                // Update state and control channels for the group members with the coordinator values
                if (stateMap.get("TransportState") != null) {
                    dispatchOnAllGroupMembers("TransportState", stateMap.get("TransportState"), "AVTransport");
                }
                // Update shuffle and repeat channels for the group members with the coordinator values
                if (stateMap.get("CurrentPlayMode") != null) {
                    dispatchOnAllGroupMembers("CurrentPlayMode", stateMap.get("CurrentPlayMode"), "AVTransport");
                }
                break;
            case "LocalGroupUUID":
                updateChannel(ZONEGROUPID);
                break;
            case "GroupCoordinatorIsLocal":
                updateChannel(LOCALCOORDINATOR);
                break;
            case "VolumeMaster":
                updateChannel(VOLUME);
                break;
            case "MuteMaster":
                updateChannel(MUTE);
                break;
            case "LineInConnected":
            case "TOSLinkConnected":
                if (SonosBindingConstants.WITH_LINEIN_THING_TYPES_UIDS.contains(getThing().getThingTypeUID())) {
                    updateChannel(LINEIN);
                }
                break;
            case "AlarmRunning":
                updateChannel(ALARMRUNNING);
                break;
            case "RunningAlarmProperties":
                updateChannel(ALARMPROPERTIES);
                break;
            case "CurrentURIFormatted":
                updateChannel(CURRENTTRACK);
                break;
            case "CurrentTitle":
                updateChannel(CURRENTTITLE);
                break;
            case "CurrentArtist":
                updateChannel(CURRENTARTIST);
                break;
            case "CurrentAlbum":
                updateChannel(CURRENTALBUM);
                break;
            case "CurrentURI":
                updateChannel(CURRENTTRANSPORTURI);
                break;
            case "CurrentTrackURI":
                updateChannel(CURRENTTRACKURI);
                break;
            case "CurrentAlbumArtURI":
                updateChannel(CURRENTALBUMARTURL);
                break;
            case "CurrentSleepTimerGeneration":
                if (value.equals("0")) {
                    updateState(SLEEPTIMER, new DecimalType(0));
                }
                break;
            case "SleepTimerGeneration":
                if (value.equals("0")) {
                    updateState(SLEEPTIMER, new DecimalType(0));
                } else {
                    updateSleepTimerDuration();
                }
                break;
            case "RemainingSleepTimerDuration":
                updateState(SLEEPTIMER, (stateMap.get("RemainingSleepTimerDuration") != null) ? new DecimalType(sleepStrTimeToSeconds(stateMap.get("RemainingSleepTimerDuration"))) : UnDefType.UNDEF);
                break;
            case "CurrentTuneInStationId":
                updateChannel(TUNEINSTATIONID);
                break;
            default:
                break;
        }
    }
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType)

Example 7 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabel_groupLabelWithValue.

@Test
public void getLabel_groupLabelWithValue() throws ItemNotFoundException {
    String testLabel = "Label [%d]";
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getState()).thenReturn(OnOffType.ON);
    when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(5));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [5]", label);
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabel_labelWithIntegerValue.

@Test
public void getLabel_labelWithIntegerValue() throws ItemNotFoundException {
    String testLabel = "Label [%d]";
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getState()).thenReturn(new DecimalType(20));
    when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [20]", label);
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class ItemUIRegistryImplTest method getLabel_labelWithDecimalValue.

@Test
public void getLabel_labelWithDecimalValue() throws ItemNotFoundException {
    String testLabel = "Label [%.3f]";
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getState()).thenReturn(new DecimalType(10f / 3f));
    when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(10f / 3f));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [3" + sep + "333]", label);
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.

the class BeaconBluetoothHandler method updateRSSI.

/**
 * Updates the RSSI channel and the Thing status according to the new received rssi value
 */
protected void updateRSSI() {
    if (device != null) {
        Integer rssi = device.getRssi();
        if (rssi != null && rssi != 0) {
            updateState(BluetoothBindingConstants.CHANNEL_TYPE_RSSI, new DecimalType(rssi));
            updateStatusBasedOnRssi(true);
        } else {
            updateState(BluetoothBindingConstants.CHANNEL_TYPE_RSSI, UnDefType.NULL);
            updateStatusBasedOnRssi(false);
        }
    }
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType)

Aggregations

DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)68 Test (org.junit.Test)33 State (org.eclipse.smarthome.core.types.State)17 PercentType (org.eclipse.smarthome.core.library.types.PercentType)16 HistoricItem (org.eclipse.smarthome.core.persistence.HistoricItem)11 StringType (org.eclipse.smarthome.core.library.types.StringType)9 HSBType (org.eclipse.smarthome.core.library.types.HSBType)8 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)7 Type (org.eclipse.smarthome.core.types.Type)7 Item (org.eclipse.smarthome.core.items.Item)6 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BigDecimal (java.math.BigDecimal)5 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 Response (javax.ws.rs.core.Response)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)3