public boolean updateIfSame(int deviceId, short pin, PinType pinType, String value) { if (isSame(deviceId, pin, pinType)) { this.dataStream.value = value; return true; } return false; }
private void preserveOldValueIfPossible(Tile[] existingTiles, Tile newTile) { for (Tile existingTile : existingTiles) { if (existingTile.templateId == newTile.templateId && newTile.updateIfSame(existingTile.deviceId, existingTile.dataStream)) { return; } } }
private void cleanPinStorage(int dashId, DeviceTiles deviceTiles, boolean removeProperties) { for (Tile tile : deviceTiles.tiles) { if (tile != null && tile.isValidDataStream()) { DataStream dataStream = tile.dataStream; pinsStorage.remove(new DashPinStorageKey(dashId, tile.deviceId, dataStream.pinType, dataStream.pin)); if (removeProperties) { for (WidgetProperty widgetProperty : WidgetProperty.getValues()) { pinsStorage.remove(new DashPinPropertyStorageKey(dashId, tile.deviceId, dataStream.pinType, dataStream.pin, widgetProperty)); } } } } }
Tile newTile = new Tile(deviceId, tileTemplate.id, null, newTileTemplate.dataStream == null ? null
private void processDeviceTile(Channel channel, DeviceTiles deviceTiles, int deviceId, long now) { for (Tile tile : deviceTiles.tiles) { if (tile.deviceId == deviceId && tile.isTicked(now)) { TileTemplate tileTemplate = deviceTiles.getTileTemplateById(tile.templateId); if (tileTemplate != null) { for (Widget tileWidget : tileTemplate.widgets) { if (tileWidget instanceof FrequencyWidget) { FrequencyWidget frequencyWidget = (FrequencyWidget) tileWidget; if (frequencyWidget.hasReadingInterval() && channel.isWritable()) { frequencyWidget.writeReadingCommand(channel); tickedWidgets++; } } } } } } }
@Override public void sendHardSync(ChannelHandlerContext ctx, int msgId, int deviceId) { for (Tile tile : tiles) { if (tile.deviceId == deviceId && tile.isValidDataStream() && tile.dataStream.isNotEmpty()) { String body = tile.dataStream.makeHardwareBody(); if (body != null) { ctx.write(makeUTF8StringMessage(HARDWARE, msgId, body), ctx.voidPromise()); } } } }
public boolean updateIfSame(int deviceId, DataStream dataStream) { if (dataStream != null) { return updateIfSame(deviceId, dataStream.pin, dataStream.pinType, dataStream.value); } return false; }
@Override public void sendAppSync(Channel appChannel, int dashId, int targetId, boolean useNewSyncFormat) { for (Tile tile : tiles) { if ((targetId == ANY_TARGET || tile.deviceId == targetId) && tile.isValidDataStream() && tile.dataStream.isNotEmpty()) { String hardBody = tile.dataStream.makeHardwareBody(); String body = prependDashIdAndDeviceId(dashId, tile.deviceId, hardBody); appChannel.write(makeUTF8StringMessage(APP_SYNC, SYNC_DEFAULT_MESSAGE_ID, body)); } } }
@Override public boolean isSame(int deviceId, short pin, PinType pinType) { for (Tile tile : tiles) { if (tile.isSame(deviceId, pin, pinType)) { return true; } } return false; }
@Override public boolean updateIfSame(int deviceId, short pin, PinType pinType, String value) { for (Tile tile : tiles) { if (tile.updateIfSame(deviceId, pin, pinType, value)) { return true; } } return false; }
public String getValue(int deviceId, short pin, PinType pinType) { for (Tile tile : tiles) { if (tile.isSame(deviceId, pin, pinType)) { return tile.dataStream.value; } } return null; }