AttributeError: 'module' object has no attribute 'setup'

Hello,

can anyone help why this script is aborting with:

16-11-02 01:28:32 homeassistant.bootstrap: Error during setup of component thermostat
Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/bootstrap.py", line 102, in _setup_component
    result = component.setup(hass, config)
AttributeError: 'module' object has no attribute 'setup'

Script: (CONFIG_DIR/custom_components/thermostat/max.py

import logging

from homeassistant.components.thermostat import ThermostatDevice
from homeassistant.const import TEMP_CELCIUS
from homeassistant.helpers.temperature import convert

from maxcube.connection import *
from maxcube.cube import *
from maxcube.device import *
from maxcube.thermostat import *


REQUIREMENTS = ['python-maxcube-api']

CONF_IP = 'ip'
CONF_PORT = 'port'
PROPERTY_SET_TEMPERATURE = 'SET_TEMPERATURE'
PROPERTY_ACTUAL_TEMPERATURE = 'ACTUAL_TEMPERATURE'
PROPERTY_MODE = 'MODE'

_LOGGER = logging.getLogger(__name__)

def setup_platform(hass, config, add_devices, discovery_info=None):

"""Setup the Max!Cube thermostat."""
devices = []
try:
    cubeConn = MaxCubeConnection(config[CONF_IP], config[CONF_PORT])
    cube = MaxCube(cubeConn)
    for device in cube.get_devices():
        devices.append(MaxThermostat(cube, device.rf_address))
except socket.error:
    _LOGGER.exception("Connection error to Max!Cube")
    return False

add_devices(devices)
return True

# pylint: disable=too-many-instance-attributes
class MaxThermostat(ThermostatDevice):
"""Representation of a Homematic thermostat."""

def __init__(self, cube, _id):
    """Initialize the thermostat."""
    self.cube = cube
    self._id = _id
    self._device = cube.device_by_rf(_id)

@property
def should_poll(self):
    """Polling needed for thermostat."""
    return True


@property
def name(self):
    """Return the name of the Homematic device."""
    return self._device.name

@property
def unit_of_measurement(self):
    """Return the unit of measurement that is used."""
    return TEMP_CELSIUS

@property
def current_temperature(self):
    """Return the current temperature."""
    return self._device.actual_temperature

@property
def target_temperature(self):
    """Return the temperature we try to reach."""
    return self._device.target_temperature

def set_temperature(self, temperature):
    """Set new target temperature."""
    self.cube.set_target_temperature(self._device, temperature)

@property
def device_state_attributes(self):
    """Return the device specific state attributes."""
    return {"mode": self._device.mode}

@property
def min_temp(self):
    """Return the minimum temperature."""
    return round(convert(4.5, TEMP_CELSIUS, self.unit_of_measurement))

@property
def max_temp(self):
    """Return the maximum temperature."""
    return round(convert(30.5, TEMP_CELSIUS, self.unit_of_measurement))

def update(self):
    """Update the data from the thermostat."""
    try:
        self.cube.update()
    except socket.error:
        _LOGGER.exception("Did not receive any temperature data from the "
                          "Max!Cube API.")

Thermostat is deprecated. It’s climate now.

I even rewrote the plugin to the climate platform and using it in the configuration.yaml, but I get the same error :frowning:

Is your intendation OK in def setup_platform?

Yes, the indentation seems off but that’s perhaps because of the copy-&-pasting. Can you give it a try with a minimal custom platform? I get way to many errors while running this code to delimit the actual issue.

Hello @fabaff,

minimal custom platform like this is working:

from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.entity import Entity


def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the sensor platform."""
    add_devices([CustomSensor()])


class CustomSensor(Entity):
    """Representation of a Sensor."""

    @property
    def name(self):
        """Return the name of the sensor."""
        return 'Example Temperature'

    @property
    def state(self):
        """Return the state of the sensor."""
        return 23

    @property
    def unit_of_measurement(self):
        """Return the unit of measurement."""
        return TEMP_CELSIUS

BUT even the honeywell platform is reproducing my issue:

- climate:
    platform: honeywell
    username: testuser

Any ideas about it or I can get closer to the issue?

Error message with only honeywell platform activated:

16-11-04 21:46:32 homeassistant.bootstrap: Error during setup of component climate
Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/bootstrap.py", line 106, in _setup_component
    result = component.setup(hass, config)
AttributeError: 'module' object has no attribute 'setup'

I also upgraded to the latest HA version without any success. Same behaviour.

@fabaff Any idea I can get closer to the issue?

You could give it a try if you setup the development environment and give the component a unique name to avoid name clashes.

And it would help if your maxcube code is available somewhere, perhaps as a PR or on http://hastebin.com/.

Sorry for the delay - Just to be sure you noticed, that I’m just using the already implemented honeywell climate component and getting the error? I’m not using a custom component at all and get the error.

@fabaff - Issue was solved and obviously caused by another configuration error in another component I had. Cannot explain why, but it solved by solving the other configuration issue.