Change to preference variable device type not recognized

Working on my first driver...

I have preferences like this:

    preferences {
    input("ip", "text", title: "IP Address", description: "[IP Address of your mochad server", required: true)
    input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
    input name: "Station", title:"X10 Station", description: "X10 Station ID"
    input name :"port", title:"Mochad port", type:"int", description: "Port for Mocha Server", required:true
}

And an initialize:
def initialize() {

if (logEnable) log.info "initialize() called"

connect(ip,port)

refresh()
}

When I click the initialize button under device I see this in the log:

[dev:84

](http://hubitat/logs#dev84)2021-05-26 09:00:36.588 pm errororg.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: user_driver_Flying_Nerd_X10_via_MochaD_495.connect() is applicable for argument types: (java.lang.String, java.lang.String) values: [192.168.0.224, 1099]

So, it HE seems to think the port parameter is a string while the connect method requires an int.

First time test, i didn't specify a type for port in the preferences. So, maybe it defaulted to string and something cached needs to be flushed to pick up the change to int?

Thanks for your attention.

Guessing which connect method you're shooting for, try this:

interfaces.rawSocket.connect(ip, port.toInteger())

Different error:

dev:842021-05-26 09:16:47.632 pm errororg.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: user_driver_Flying_Nerd_X10_via_MochaD_495.refresh() is applicable for argument types: () values: Possible solutions: every(), parse(java.lang.String), every(groovy.lang.Closure), grep() (initialize)

Mind posting your whole code for context?

Incidentally, you also need to implement these methods:

parse(String message) - This method is called with any incoming messages from the socket server. This is a standard method for drivers.

socketStatus(String message) - This method is called with any status messages from the socket client connection (disconnections, errors during connect, etc)

There will be no incoming messages from the socket server. Do I need to implement a function with nothing in it?

Don't laught... The driver is just a start--I'll be adding sendMessage commands in the on and off methods: But, I figured first step was to get the socket to open in an initialize. But, maybe I need to open and close after each on/off invocation?

    def version() {"v0.1"}

import hubitat.helper.InterfaceUtils

metadata {
    definition (name: "X10 via MochaD", namespace: "Flying-Nerd", author: "Dave Thomas") {
        capability "Initialize"
        capability "Switch"

    }
}

preferences {
    input("ip", "text", title: "IP Address", description: "[IP Address of your mochad server", required: true)
    input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
    input name: "Station", title:"X10 Station", description: "X10 Station ID"
    input name :"port", title:"Mochad port", type:"text", description: "Port for Mocha Server", required:true
}


def on() {
    if (logEnable) log.debug "Sending on request to [${settings.ip}]"
    sendEvent(name: "switch", value: "on", isStateChange: true)
}
def off() {
    if (logEnable) log.debug "Sending off request to [${settings.ip}]"
    sendEvent(name: "switch", value: "off", isStateChange: true)
}
def initialize() {

    if (logEnable) log.info "initialize() called"
    interfaces.rawSocket.connect(ip, 1099)
	//connect(ip,port.toInt())
    //refresh()
}

def parse(String description) {
    if (logEnable) log.debug(description)
}

This version went back to trying "text" as the device type for port, thinking maybe the toInt() would only work on a text type. And then, I hard coded the port number--still I get an error:

0

21-05-26 09:28:42.105 pm errororg.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: user_driver_Flying_Nerd_X10_via_MochaD_495.refresh() is applicable for argument types: () values:

That doesn't look like a bad start.

I don't see anything calling refresh(), since you have it commented out. Are you sure this is the version you were running when you got that debug print?

Yes, I would advise you to have implementations of both parse and socketStatus, even if they just log their message (or even do nothing at all).

Also, toInt() won't work. You have to use the full toInteger().

1 Like

Declaring the preference as string and using toInteger() (vs. toInt) eliminated the error!

Got to hang it up tonight, thanks for the fast reply.

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.