Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[panasonictv] Panasonic Viera TV Binding initial contribution #4407

Closed
wants to merge 1 commit into from

Conversation

scienty
Copy link

@scienty scienty commented Dec 18, 2018

Expected Behavior

Enhancement, implement panasonictv binding for oh2 using upnp services
Legacy binding for panasonictv works in many cases but there are better features in oh2 to handle upnp communication and discovery

Fixes #3904

@wborn wborn added the new binding If someone has started to work on a binding. For a new binding PR. label Dec 18, 2018
Signed-off-by: Prakashbabu Sidaraddi <e.prakashs@gmail.com> (github:
scienty)
@wborn wborn changed the title Panasonic Viera TV binding for openhab2 [panasonictv] Panasonic Viera TV Binding initial contribution Dec 18, 2018
@scienty
Copy link
Author

scienty commented Dec 20, 2018

Would someone please do a code review and merge. Have been testing this continuously for 2 months in my home setup and it worked as expected. The code structure has been derived from samsungtv binding.

@Flole998
Copy link
Member

You're not detecting online/offline of the TV as far as I can see, right? There is a subscription you can use and it will do a callback on power change to a URL (I think you can specify that URL aswell). My modification of the openhab1 binding simple has another webserver for that, it's not published anywhere though :D

@scienty
Copy link
Author

scienty commented Jan 3, 2019

You're not detecting online/offline of the TV as far as I can see, right? There is a subscription you can use and it will do a callback on power change to a URL (I think you can specify that URL aswell). My modification of the openhab1 binding simple has another webserver for that, it's not published anywhere though :D

@Flole998 would you please provide sample code for that? I have been using it for couple of months with my Panasonic TV, even online and offline state for the thing is changed properly via UPNP service.

I have a openhab rule configured to wait for the TV to come online from cold start, then check the switch status. Based on that the rule send keycode to switch appropriate HDMI.

@scienty
Copy link
Author

scienty commented Jan 3, 2019

@cweitkamp @kaikreuzer @martinvw @wborn please review and approve the pull request.

Appreciate your time.
Thanks.

@scienty
Copy link
Author

scienty commented Jan 10, 2019

@cweitkamp @kaikreuzer @martinvw @wborn please review and approve the pull request.

Appreciate your time.
Thanks.

@cweitkamp @kaikreuzer @martinvw @wborn Need your precious time to get this into main stream. Please do the needful.

Thanks,
Prakash

@Flole998
Copy link
Member

Sorry totally forgot about this, the code for having the TV push it's powerstate is this (it is in no way complete, perfect or even good, it's just a proof of concept or a hacky way I used for 2 years already). It requires some option to be enabled (I think) so the TV doesn't enter it's real power saving mode, my TV wakes up instantly when pushing the button and updates the status immediately:

 java.util.ArrayList<String> Subscribed = new ArrayList<String>();

    void servmain() {
        try {
            Soc = new ServerSocket(51218);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            logger.error("Could not bind to Socket!");
            return;
        }
        for (PanasonicTVBindingProvider provider : this.providers) {
            for (String itemName : provider.getItemNames()) {
                PanasonicTVBindingConfig config = provider.getBindingConfigForItem(itemName);
                if (!Subscribed.contains(registeredTVs.get(config.getTv()))) {
                    if (subscribe(getIP(), registeredTVs.get(config.getTv()).replaceAll("0*([0-9]+)", "$1"))) {
                        Subscribed.add(registeredTVs.get(config.getTv()));
                        logger.info("Subscribed to Updates of "
                                + registeredTVs.get(config.getTv()).replaceAll("0*([0-9]+)", "$1") + "!");
                    } else {
                        logger.error("Could not subscribe to Updates of "
                                + registeredTVs.get(config.getTv()).replaceAll("0*([0-9]+)", "$1") + "!");
                    }
                }
            }
        }
        new Thread(new Server(Soc, eventPublisher, providers, logger)).start();

    }

    String getIP() {
        Enumeration<NetworkInterface> interfaces = null;
        try {
            interfaces = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            // handle error
        }

        if (interfaces != null) {
            while (interfaces.hasMoreElements()) {
                NetworkInterface i = interfaces.nextElement();
                Enumeration<InetAddress> addresses = i.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    InetAddress address = addresses.nextElement();
                    if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) {
                        return address.getHostAddress();
                    }
                }
            }
        }
        return null;
    }

    boolean subscribe(final String myip, final String tvip) {
        if (!active) {
            return true;
        }
        Socket pingSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;

        try {
            pingSocket = new Socket(tvip, 55000);
            out = new PrintWriter(pingSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(pingSocket.getInputStream()));
            out.print("SUBSCRIBE /nrc/event_0 HTTP/1.1");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("User-Agent: OpenHAB/2.0");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("Host: " + tvip + ":55000");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("CALLBACK: <http://" + myip + ":51218/nrc>");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("NT: upnp:event");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("TIMEOUT: Second-300");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            String read = in.readLine();
            if (read == null) {
                logger.info("Subscription to " + tvip + " failed: Data Missing ");
                out.close();
                timer.schedule(new java.util.TimerTask() {
                    @Override
                    public void run() {
                        logger.info("Trying again to subscribe to Updates of " + tvip + "");
                        // System.out.println("Trying again to subscribe");
                        subscribe(myip, tvip);
                    }
                }, 5000);
                pingSocket.close();
                return false;
            }
            if (!read.contains("200")) {
                logger.info("Subscription on " + tvip + " failed with error " + read);
                out.close();
                timer.schedule(new java.util.TimerTask() {
                    @Override
                    public void run() {
                        logger.info("Trying again to subscribe to Updates of " + tvip + "");
                        // System.out.println("Trying again to subscribe");
                        subscribe(myip, tvip);
                    }
                }, 5000);
                pingSocket.close();
                return false;
            }

            while (in.ready()) {
                read = in.readLine();
                if (read.startsWith("SID: ")) {
                    sid = read;
                }
            }
            out.close();
            timer.schedule(new java.util.TimerTask() {
                @Override
                public void run() {
                    // System.out.println("Resubscribing");
                    unsubscribe(tvip);
                    subscribe(myip, tvip);
                }
            }, 290000);
            pingSocket.close();
            return true;
        } catch (IOException e) {
            logger.error("Subscription error on " + tvip + ": " + e.toString());
            return false;
        }

    }

    void unsubscribe(final String tvip) {
        Socket pingSocket = null;
        PrintWriter out = null;
        try {
            pingSocket = new Socket(tvip, 55000);
            out = new PrintWriter(pingSocket.getOutputStream(), true);
            out.print("UNSUBSCRIBE /nrc/event_0 HTTP/1.1");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("User-Agent: OpenHAB/2.0");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("Host: " + tvip + ":55000");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print(sid);
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            /*
             * System.out.println(in.readLine());
             * while(in.ready()){
             * System.out.println(in.readLine());
             * }
             */
            out.close();
            pingSocket.close();
        } catch (IOException e) {
            return;
        }

    }

}

class Server implements Runnable {

    private ServerSocket Soc;
    private EventPublisher publisher;
    private Collection<PanasonicTVBindingProvider> providers;
    private Logger mylogger;

    Server(ServerSocket CSoc1, EventPublisher publisher1, Collection<PanasonicTVBindingProvider> providers1,
            Logger logger) {
        Soc = CSoc1;
        publisher = publisher1;
        providers = providers1;
        mylogger = logger;
    }

    @Override
    public void run() {
        Socket CSoc = null;
        while (!Soc.isClosed()) {
            try {
                CSoc = Soc.accept();
                new Thread(new AcceptNewClient(CSoc, publisher, providers, mylogger)).start();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                } catch (Exception e) {
                }
            }
        }
    }
}

class AcceptNewClient implements Runnable {
    Socket ClientSocket;
    DataInputStream din;
    DataOutputStream dout;
    Socket CSoc;
    EventPublisher publisher;
    Collection<PanasonicTVBindingProvider> providers;
    Logger logger;

    AcceptNewClient(Socket CSoc, EventPublisher publisher, Collection<PanasonicTVBindingProvider> providers,
            Logger logger) {
        this.CSoc = CSoc;
        this.publisher = publisher;
        this.providers = providers;
        this.logger = logger;
    }

    @Override
    public void run() {
        try {
            ClientSocket = CSoc;
            logger.debug("Client Connected ...");
            InputStream socketinstr;

            socketinstr = ClientSocket.getInputStream();

            InputStreamReader isr = new InputStreamReader(socketinstr);
            BufferedReader br = new BufferedReader(isr);
            while (!ClientSocket.isClosed()) {
                int i = 0;
                while (!br.ready()) {
                    try {
                        Thread.sleep(1);
                        i++;
                        if (i > 500) {
                            logger.error("TIMEOUT!");
                            ClientSocket.close();
                            return;
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        ClientSocket.close();
                        return;
                    }
                }
                String read = br.readLine();
                // logger.error(read);
                if (read.startsWith("  <X_ScreenState>o")) {
                    for (PanasonicTVBindingProvider provider : providers) {
                        for (String itemName : provider.getItemNames()) {
                            if (provider.getBindingConfigForItem(itemName).getCommand().equals("POWER")) {
                                if (read.substring(read.indexOf(">") + 1, read.lastIndexOf("<")).equals("on")) {
                                    provider.getBindingConfigForItem(itemName).setStatus(true);
                                    publisher.postUpdate(itemName, OnOffType.ON);
                                } else if (read.substring(read.indexOf(">") + 1, read.lastIndexOf("<")).equals("off")) {
                                    provider.getBindingConfigForItem(itemName).setStatus(false);
                                    publisher.postUpdate(itemName, OnOffType.OFF);
                                }
                                ClientSocket.close();
                            }
                        }
                    }
                    break;
                }
                // System.out.println(ClientSocket.isConnected());
            }
            logger.debug("Client disconnected");
            if (!ClientSocket.isClosed()) {
                ClientSocket.close();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

@scienty
Copy link
Author

scienty commented Feb 20, 2019

Sorry totally forgot about this, the code for having the TV push it's powerstate is this (it is in no way complete, perfect or even good, it's just a proof of concept or a hacky way I used for 2 years already). It requires some option to be enabled (I think) so the TV doesn't enter it's real power saving mode, my TV wakes up instantly when pushing the button and updates the status immediately:

 java.util.ArrayList<String> Subscribed = new ArrayList<String>();

    void servmain() {
        try {
            Soc = new ServerSocket(51218);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            logger.error("Could not bind to Socket!");
            return;
        }
        for (PanasonicTVBindingProvider provider : this.providers) {
            for (String itemName : provider.getItemNames()) {
                PanasonicTVBindingConfig config = provider.getBindingConfigForItem(itemName);
                if (!Subscribed.contains(registeredTVs.get(config.getTv()))) {
                    if (subscribe(getIP(), registeredTVs.get(config.getTv()).replaceAll("0*([0-9]+)", "$1"))) {
                        Subscribed.add(registeredTVs.get(config.getTv()));
                        logger.info("Subscribed to Updates of "
                                + registeredTVs.get(config.getTv()).replaceAll("0*([0-9]+)", "$1") + "!");
                    } else {
                        logger.error("Could not subscribe to Updates of "
                                + registeredTVs.get(config.getTv()).replaceAll("0*([0-9]+)", "$1") + "!");
                    }
                }
            }
        }
        new Thread(new Server(Soc, eventPublisher, providers, logger)).start();

    }

    String getIP() {
        Enumeration<NetworkInterface> interfaces = null;
        try {
            interfaces = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            // handle error
        }

        if (interfaces != null) {
            while (interfaces.hasMoreElements()) {
                NetworkInterface i = interfaces.nextElement();
                Enumeration<InetAddress> addresses = i.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    InetAddress address = addresses.nextElement();
                    if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) {
                        return address.getHostAddress();
                    }
                }
            }
        }
        return null;
    }

    boolean subscribe(final String myip, final String tvip) {
        if (!active) {
            return true;
        }
        Socket pingSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;

        try {
            pingSocket = new Socket(tvip, 55000);
            out = new PrintWriter(pingSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(pingSocket.getInputStream()));
            out.print("SUBSCRIBE /nrc/event_0 HTTP/1.1");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("User-Agent: OpenHAB/2.0");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("Host: " + tvip + ":55000");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("CALLBACK: <http://" + myip + ":51218/nrc>");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("NT: upnp:event");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("TIMEOUT: Second-300");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            String read = in.readLine();
            if (read == null) {
                logger.info("Subscription to " + tvip + " failed: Data Missing ");
                out.close();
                timer.schedule(new java.util.TimerTask() {
                    @Override
                    public void run() {
                        logger.info("Trying again to subscribe to Updates of " + tvip + "");
                        // System.out.println("Trying again to subscribe");
                        subscribe(myip, tvip);
                    }
                }, 5000);
                pingSocket.close();
                return false;
            }
            if (!read.contains("200")) {
                logger.info("Subscription on " + tvip + " failed with error " + read);
                out.close();
                timer.schedule(new java.util.TimerTask() {
                    @Override
                    public void run() {
                        logger.info("Trying again to subscribe to Updates of " + tvip + "");
                        // System.out.println("Trying again to subscribe");
                        subscribe(myip, tvip);
                    }
                }, 5000);
                pingSocket.close();
                return false;
            }

            while (in.ready()) {
                read = in.readLine();
                if (read.startsWith("SID: ")) {
                    sid = read;
                }
            }
            out.close();
            timer.schedule(new java.util.TimerTask() {
                @Override
                public void run() {
                    // System.out.println("Resubscribing");
                    unsubscribe(tvip);
                    subscribe(myip, tvip);
                }
            }, 290000);
            pingSocket.close();
            return true;
        } catch (IOException e) {
            logger.error("Subscription error on " + tvip + ": " + e.toString());
            return false;
        }

    }

    void unsubscribe(final String tvip) {
        Socket pingSocket = null;
        PrintWriter out = null;
        try {
            pingSocket = new Socket(tvip, 55000);
            out = new PrintWriter(pingSocket.getOutputStream(), true);
            out.print("UNSUBSCRIBE /nrc/event_0 HTTP/1.1");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("User-Agent: OpenHAB/2.0");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print("Host: " + tvip + ":55000");
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            out.print(sid);
            out.flush();
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            pingSocket.getOutputStream().write(0x0d);
            pingSocket.getOutputStream().write(0x0a);
            /*
             * System.out.println(in.readLine());
             * while(in.ready()){
             * System.out.println(in.readLine());
             * }
             */
            out.close();
            pingSocket.close();
        } catch (IOException e) {
            return;
        }

    }

}

class Server implements Runnable {

    private ServerSocket Soc;
    private EventPublisher publisher;
    private Collection<PanasonicTVBindingProvider> providers;
    private Logger mylogger;

    Server(ServerSocket CSoc1, EventPublisher publisher1, Collection<PanasonicTVBindingProvider> providers1,
            Logger logger) {
        Soc = CSoc1;
        publisher = publisher1;
        providers = providers1;
        mylogger = logger;
    }

    @Override
    public void run() {
        Socket CSoc = null;
        while (!Soc.isClosed()) {
            try {
                CSoc = Soc.accept();
                new Thread(new AcceptNewClient(CSoc, publisher, providers, mylogger)).start();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                } catch (Exception e) {
                }
            }
        }
    }
}

class AcceptNewClient implements Runnable {
    Socket ClientSocket;
    DataInputStream din;
    DataOutputStream dout;
    Socket CSoc;
    EventPublisher publisher;
    Collection<PanasonicTVBindingProvider> providers;
    Logger logger;

    AcceptNewClient(Socket CSoc, EventPublisher publisher, Collection<PanasonicTVBindingProvider> providers,
            Logger logger) {
        this.CSoc = CSoc;
        this.publisher = publisher;
        this.providers = providers;
        this.logger = logger;
    }

    @Override
    public void run() {
        try {
            ClientSocket = CSoc;
            logger.debug("Client Connected ...");
            InputStream socketinstr;

            socketinstr = ClientSocket.getInputStream();

            InputStreamReader isr = new InputStreamReader(socketinstr);
            BufferedReader br = new BufferedReader(isr);
            while (!ClientSocket.isClosed()) {
                int i = 0;
                while (!br.ready()) {
                    try {
                        Thread.sleep(1);
                        i++;
                        if (i > 500) {
                            logger.error("TIMEOUT!");
                            ClientSocket.close();
                            return;
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        ClientSocket.close();
                        return;
                    }
                }
                String read = br.readLine();
                // logger.error(read);
                if (read.startsWith("  <X_ScreenState>o")) {
                    for (PanasonicTVBindingProvider provider : providers) {
                        for (String itemName : provider.getItemNames()) {
                            if (provider.getBindingConfigForItem(itemName).getCommand().equals("POWER")) {
                                if (read.substring(read.indexOf(">") + 1, read.lastIndexOf("<")).equals("on")) {
                                    provider.getBindingConfigForItem(itemName).setStatus(true);
                                    publisher.postUpdate(itemName, OnOffType.ON);
                                } else if (read.substring(read.indexOf(">") + 1, read.lastIndexOf("<")).equals("off")) {
                                    provider.getBindingConfigForItem(itemName).setStatus(false);
                                    publisher.postUpdate(itemName, OnOffType.OFF);
                                }
                                ClientSocket.close();
                            }
                        }
                    }
                    break;
                }
                // System.out.println(ClientSocket.isConnected());
            }
            logger.debug("Client disconnected");
            if (!ClientSocket.isClosed()) {
                ClientSocket.close();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Thanks @Flole998. Will check what improvements can be done with this and incorporate.

@Hilbrand Hilbrand added the oh1 migration Relates to migrating an openHAB 1 addon to openHAB 2 label Sep 13, 2019
@volbrene
Copy link

volbrene commented Sep 19, 2019

Hello,
is this pull request fix my issue?

https://github.com/openhab/openhab2-addons/issues/6104#issue-495903713

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/panasonictv-binding-upgrade-to-openhab-2-x/82445/3

@Flole998
Copy link
Member

@scienty Did you have a chance to add the listener for power state changes? I think that could be one of the reasons this PR hasn't been reviewed yet.

Unfortunately most of my code is "bad" or at least redundant (and the "integrated" OH Functions should be used instead (for example for getting the IP Address or serving a HTTP Request) based on "todays" OH2 standards, "back then" in OH1 days this was (almost) the only way to solve this and I never really got into OH2 development, otherwise I would have done this myself already.

Copy link
Member

@Hilbrand Hilbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scienty thank you for your contributions. Apparently it took some time for someone to review. Sorry for that. I did an initial review. Most part of the code looks fine. Some methods are a bit complex, making it harder to understand what is going on.

This pr is already somewhat older and since then a number of things have changed. Most importantly the build system has changed. You need to migrate the binding first before getting it merged. There is a complete tutorial on how to migrate: https://community.openhab.org/t/tutorial-migrate-your-binding-to-the-maven-bnd-based-build-system/81389

*/
public class PanasonicTvHandler extends BaseThingHandler implements DiscoveryListener, RegistryListener, EventListener {

private Logger logger = LoggerFactory.getLogger(PanasonicTvHandler.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private Logger logger = LoggerFactory.getLogger(PanasonicTvHandler.class);
private Logger final logger = LoggerFactory.getLogger(PanasonicTvHandler.class);

public class PanasonicTvHandlerFactory extends BaseThingHandlerFactory {

private static final Collection<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Lists
.newArrayList(PANASONIC_TV_THING_TYPE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove dependency on google guava, use: Arrays.asList.

String label = "Panasonic TV";
try {
label = device.getDetails().getFriendlyName();
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you catch the specific exception here instead of the general Exception? This looks like a lazy way to avoid null checks?

final ActionArgumentValue newArgument;
try {
newArgument = result.get(variable);
} catch (final Exception ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you catch the specific exception here?

if (newArgument.getValue() != null) {
resultMap.put(variable, newArgument.getValue().toString());
}
} catch (final Exception ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you catch the specific exception here?

PanasonicTvUtils.buildHashMap("InstanceID", "0", "Channel", "Master"));
updateResourceState("RenderingControl", "GetMute",
PanasonicTvUtils.buildHashMap("InstanceID", "0", "Channel", "Master"));
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you catch the specific exception?

*/
public class RemoteControllerService implements UpnpIOParticipant, PanasonicTvService {

private Logger logger = LoggerFactory.getLogger(RemoteControllerService.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private Logger logger = LoggerFactory.getLogger(RemoteControllerService.class);
private final Logger logger = LoggerFactory.getLogger(RemoteControllerService.class);


static final String SERVICE_NAME = "p00RemoteController";

private Map<String, String> stateMap = Collections.synchronizedMap(new HashMap<String, String>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private Map<String, String> stateMap = Collections.synchronizedMap(new HashMap<String, String>());
private Map<String, String> stateMap = new ConcurrentHashMap<String, String>());

*
* @param key Button code to send
*/
private static final List<String> tvInputKeyCodes = Arrays.asList("NRC_HDMI1-ONOFF", "NRC_HDMI2-ONOFF",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put all fields at the top of the class.

return null;
}

// TODO: remove manual connection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this code if it's not used.

@Hilbrand Hilbrand added the awaiting feedback Awaiting feedback from the pull request author label Nov 25, 2019
@martinvw
Copy link
Member

@scienty what is the status of this binding? Are you planning on finishing it? Thanks for your work!

@cpmeister cpmeister added the stale As soon as a PR is marked stale, it can be removed 6 months later. label Apr 9, 2020
@Hilbrand
Copy link
Member

@scienty closing this pr due to long time no activity. If you still want to finish this work, which would be great, you can reopen this pr or if you need advice let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback Awaiting feedback from the pull request author new binding If someone has started to work on a binding. For a new binding PR. oh1 migration Relates to migrating an openHAB 1 addon to openHAB 2 stale As soon as a PR is marked stale, it can be removed 6 months later.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants