rcastberg / sure_petcare

Python library for accessing sure connect petflap
GNU General Public License v3.0
55 stars 15 forks source link

Home Assistant #5

Open dib0 opened 5 years ago

dib0 commented 5 years ago

Nice work on the surepet support!

I'm trying to get the home assistant sensor working, but I keep getting the following error:

Error while setting up platform sure_petflap Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform SLOW_SETUP_MAX_WAIT, loop=hass.loop) File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/home/hass/.homeassistant/custom_components/sensor/sure_petflap.py", line 59, in setup_platform username = config.get(CONF_USERNAME) NameError: name 'CONF_USERNAME' is not defined

I'm not sure what goes wrong. The code looks alright. I'm running hass 0.80.2. any Ideas?

Jbossalini commented 5 years ago

I think the eval under def is_hass_component(): is not working. As a hack, I commented out that block, commented the if start/stop, updated the indentation for the remaining lines within the if, and then commented everything in the else block.

#def is_hass_component():
#    try:
#        import homeasssistant
#        return True
#    except ImportError:
#        return False

#if is_hass_component():
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD)
import homeassistant.helpers.config_validation as cv

from deps.sure_petcare import SurePetFlap
from deps.sure_petcare.utils import gen_device_id

import voluptuous as vol

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_USERNAME): cv.string,
    vol.Required(CONF_PASSWORD): cv.string,
})
#else:
    # Assume not running within home assistant.  This *does* mean that you
    # won't be able to run this test script if you have homeassistant
    # installed but, if you do, you're probably running (or can run) this
    # component from within hass anyway.
#    from sure_petcare import SurePetFlap
#    from sure_petcare.utils import gen_device_id

    # dummy dependencies
#    class Entity( object ):
#        pass

#    def Throttle( *args, **kwargs ):
#        def decorator( f ):
#            return f
#        return decorator

I plan on returning to this shortly to figure out a permanent fix.