]> git.basschouten.com Git - openhab-addons.git/blob
09a12709ec7b5977386ea856598e21990cc518d3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.http.internal.converter;
14
15 import java.util.function.Consumer;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.http.internal.http.Content;
19 import org.openhab.core.library.types.RawType;
20 import org.openhab.core.types.Command;
21 import org.openhab.core.types.State;
22
23 /**
24  * The {@link ImageItemConverter} implements {@link org.openhab.core.library.items.ImageItem} conversions
25  *
26  * @author Jan N. Klug - Initial contribution
27  */
28
29 @NonNullByDefault
30 public class ImageItemConverter implements ItemValueConverter {
31     private final Consumer<State> updateState;
32
33     public ImageItemConverter(Consumer<State> updateState) {
34         this.updateState = updateState;
35     }
36
37     @Override
38     public void process(Content content) {
39         String mediaType = content.getMediaType();
40         updateState.accept(
41                 new RawType(content.getRawContent(), mediaType != null ? mediaType : RawType.DEFAULT_MIME_TYPE));
42     }
43
44     @Override
45     public void send(Command command) {
46         throw new IllegalStateException("Read-only channel");
47     }
48 }