mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Improved onewire configuration
This commit is contained in:
parent
8842e4e94f
commit
ce501ae627
@ -17,34 +17,25 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
""" Sets up the one wire Sensors"""
|
""" 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 == []:
|
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
|
return
|
||||||
|
|
||||||
devs = []
|
devs = []
|
||||||
names = []
|
names = SENSOR_IDS
|
||||||
try:
|
|
||||||
|
for key in config.keys():
|
||||||
|
if key=="names":
|
||||||
## only one name given
|
## only one name given
|
||||||
if type(config['names']) == str:
|
if isinstance(config['names'], str):
|
||||||
names = config[names]
|
names = [config['names']]
|
||||||
|
|
||||||
## map names and sensors in given order
|
## map names and sensors in given order
|
||||||
elif type(config['names']) == list:
|
elif isinstance(config['names'], list):
|
||||||
names = config['names']
|
names = config['names']
|
||||||
|
## map names to ids.
|
||||||
## map names with ids
|
elif isinstance(config['names'], dict):
|
||||||
elif type(config['names']) == dict:
|
names = [config['names'].get(sensor_id, sensor_id) for sensor_id in SENSOR_IDS]
|
||||||
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 device_file, name in zip(DEVICE_FILES, names):
|
for device_file, name in zip(DEVICE_FILES, names):
|
||||||
devs.append(OneWire(name, device_file, TEMP_CELCIUS))
|
devs.append(OneWire(name, device_file, TEMP_CELCIUS))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user