From b3683887147dd3031b8dc844d355d6e3e16b62c3 Mon Sep 17 00:00:00 2001 From: deisi Date: Wed, 16 Sep 2015 08:49:12 +0200 Subject: [PATCH 1/2] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c7e72545bf6..65c584d143a 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,5 @@ nosetests.xml # Hide emacs backups *~ +*# +*.orig From b6f954e082c171721ef177bd89d2218838274fdf Mon Sep 17 00:00:00 2001 From: deisi Date: Wed, 16 Sep 2015 10:18:11 +0200 Subject: [PATCH 2/2] Changed handling of config file I tried to implement your suggesteions for the default handlig of the device names. I think this way, everything you wanted is in. --- homeassistant/components/sensor/onewire.py | 39 +++++++++------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/sensor/onewire.py b/homeassistant/components/sensor/onewire.py index c3e0b5e3e9c..bb2a0438a75 100644 --- a/homeassistant/components/sensor/onewire.py +++ b/homeassistant/components/sensor/onewire.py @@ -17,35 +17,26 @@ _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the one wire Sensors""" - # TODO check if kernel modules are loaded - # TODO implment config fore the name, but also default solution if DEVICE_FILES == []: - _LOGGER.error('No onewire sensor found') + _LOGGER.error('No onewire sensor found. Check if dtoverlay=w1-gpio,gpiopin=4 is in your /boot/config.txt and the correct gpiopin number is set.') return devs = [] - names = [] - try: - ## only one name given - if type(config['names']) == str: - names = config[names] - - ## map names and sensors in given order - elif type(config['names']) == list: - names = config['names'] + names = SENSOR_IDS - ## map names with ids - elif type(config['names']) == dict: - for sensor_id in SENSOR_IDS: - names.append(config['names'][sensor_id]) - - except KeyError: - ## use id as name - if not config['names']: - for sensor_id in SENSOR_IDS: - names.append(sensor_id) - + for key in config.keys(): + if key=="names": + ## only one name given + if isinstance(config['names'], str): + names = [config['names']] + ## map names and sensors in given order + elif isinstance(config['names'], list): + names = config['names'] + ## map names to ids. + elif isinstance(config['names'], dict): + names = [config['names'].get(sensor_id, sensor_id) for sensor_id in SENSOR_IDS] + for device_file, name in zip(DEVICE_FILES, names): devs.append(OneWire(name, device_file, TEMP_CELCIUS)) add_devices(devs) @@ -90,4 +81,4 @@ class OneWire(Entity): @property def unit_of_measurement(self): return self._unit_of_measurement - \ No newline at end of file +