Hi folks,
Apologies in advance for the ham-handed approach, but I’m a pretty miserable programmer. I’m integrating the Digital Loggers DIN III Relay in - actually, I have that working fine. It’s an eight port, internet addressable relay. Only I’ve found I have to hard code the settings. I don’t know enough object oriented programming to follow how the homeassistant.component.switch and voluptuous works. I program by example and pattern matching and it’s just failing me here.
I’ve used the AwsomeLights example and referenced the existing Netio and MyStrom custom switches as examples.
Here’s a section that happens to be working, but with the stuff I thought would work commented out.
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
# from homeassistant.const import (CONF_HOST, CONF_CONTROLLERNAME, CONF_USERNAME, CONF_PASSWORD, CONF_TIMEOUT, CONF_CYCLETIME)
from homeassistant.const import (CONF_HOST, CONF_USERNAME, CONF_PASSWORD)
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['dlipower==0.7.165']
DEFAULT_CONTROLLERNAME = 'DINRelay'
DEFAULT_USERNAME = 'admin'
DEFAULT_PASSWORD = 'admin'
DEFAULT_TIMEOUT = 20
DEFAULT_CYCLETIME = 3
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
# vol.Optional(CONF_CONTROLLERNAME, default=DEFAULT_CONTROLLERNAME): cv.string,
vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string,
# vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT):
# vol.All(vol.Coerce(int), vol.Range(min=1, max=600)),
# vol.Optional(CONF_CYCLETIME, default=DEFAULT_CYCLETIME):
# vol.All(vol.Coerce(int), vol.Range(min=1, max=600)),
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Find and return DIN III Relay switch."""
import dlipower
host = config.get(CONF_HOST)
# controllername = config.get(CONF_CONTROLLERNAME)
user = config.get(CONF_USERNAME)
pswd = config.get(CONF_PASSWORD)
# tout = config.get(CONF_TIMEOUT)
# cycl = config.get(CONF_CYCLETIME)
# host = '127.0.0.1'
controllername = 'PoolRelay'
# user = 'admin'
# pswd = 'admin'
tout = 20
cycl = 3
Is there something special about host, username and password that that exist in the schema and the other things don’t? Or I’m looking at it assuming that the configuration smarts do some magic converting the yaml into things that will import of the form CONF_something. I don’t see why it would do that… other than that’s what every example I look at seems to have. Obviously, at the end I’m just accommodating the fact that it isn’t working and hard coding my stuff. My intended configuration.yaml would look like this:
switch:
- platform: digitalloggers
host: !secret pool_relay_address
controllername: PoolRelays
password: !secret pool_relay_password
I know I’m missing something pretty fundamental. I’m not new to python, though I’m not formally a programmer. I’ve not dealt with yaml before HA and I’ve never worked with voluptuous. Likewise, despite that I have the full eight ports of the relay showing up, updating and interacting with HA, I know there are still a few things to fix on it. It’s flooding the poor relay with requests for updates. I’ll need to borrow the throttling concept I’ve seen on some of the other custom switches and apply it here.
Please either tell me outright what I’m doing wrong or point me towards the resource to enlighten me. I’ve been searching all over the HA site and forum but I think I’m probably not searching for the right thing or looking for something so basic you folks just aren’t even talking about it.
Thanks!
Dave