Hello,
Here are some more information about my code. Please tell me if it is enough ? Because I still can’t get it to work.
Configuration.yaml. My custom component protexiom.
protexiom:
scan_interval: 20
url: !secret protexiom_url
My init.py file for my custom component.
import voluptuous as vol
from homeassistant.const import CONF_URL, CONF_PASSWORD, CONF_SCAN_INTERVAL
from homeassistant.helpers import config_validation as cv, discovery
from homeassistant.helpers.entity import Entity
from .const import DOMAIN, SENSOR_TYPES, PROTEXIOM_COMPONENTS, PROTEXIOM_DEVICES_TYPE, CONF_CODES, DEFAULT_SCAN_INTERVAL
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_URL): cv.string,
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): cv.time_period,
}
)
},
extra=vol.ALLOW_EXTRA,
)
def setup(hass, config):
url = config[DOMAIN][CONF_URL]
try:
protexiom = Protexiom(url)
except:
_LOGGER.exception("Error when trying to log in")
return False
for component in PROTEXIOM_COMPONENTS:
_LOGGER.info("Components : ")
_LOGGER.info(component)
discovery.load_platform(hass, component, DOMAIN, {}, config)
return True
And my binary_sensor.py :
import voluptuous as vol
from homeassistant.components.binary_sensor import *
from homeassistant.const import (
STATE_OFF,
STATE_ON,
)
from . import DOMAIN as PROTEXIOM_DOMAIN
from .const import *
_LOGGER = logging.getLogger(__name__)
DEFAULT_DEVICE_CLASS = "None"
SCAN_INTERVAL = timedelta(minutes=2)
def setup_platform(hass, config, add_entities, discovery_info=None):
_hass = hass
controller = hass.data[PROTEXIOM_DOMAIN]["controller"]
protexiom_devices = []
for device, deviceTypeList in hass.data[PROTEXIOM_DOMAIN]["devices"].items():
protexiom_devices.append(ProtexiomBinarySensor(hass, controller, device, deviceType))
add_entities(protexiom_devices, True)
class ProtexiomBinarySensor(BinarySensorDevice):
def __init__(self, hass, protexiom, protexiom_device, deviceType):
self.protexiom = protexiom
self._attributes = {}
self._state = None
self._state_attr = {}
self._hass = hass
self._device = protexiom_device
self._name = "protexiom_"+self._device+"_"+SENSOR_TYPES[deviceType][0]
self._fname = ""
self._deviceType = deviceType
def update(self):
return protexiom.get_value()