mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Refactoring the code for pylint & flake test
This commit is contained in:
parent
174aeacd76
commit
d64f0ddd41
@ -33,17 +33,18 @@ REQUIREMENTS = ['https://github.com/Danielhiversen/pyRFXtrx/archive/' +
|
|||||||
'ec7a1aaddf8270db6e5da1c13d58c1547effd7cf.zip#RFXtrx==0.15']
|
'ec7a1aaddf8270db6e5da1c13d58c1547effd7cf.zip#RFXtrx==0.15']
|
||||||
|
|
||||||
DOMAIN = "rfxtrx"
|
DOMAIN = "rfxtrx"
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Setup the RFXtrx platform. """
|
""" Setup the RFXtrx platform. """
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
# Add light from config file
|
# Add light from config file
|
||||||
lights = []
|
lights = []
|
||||||
devices = config.get('devices')
|
devices = config.get('devices')
|
||||||
for entity_id, entity_name in devices.items():
|
for entity_id, entity_name in devices.items():
|
||||||
if entity_id not in rfxtrx.RFX_DEVICES:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
logger.info("Add %s rfxtrx.light" % entity_name)
|
_LOGGER.info("Add %s rfxtrx.light", entity_name)
|
||||||
new_light = RfxtrxLight(entity_name, False)
|
new_light = RfxtrxLight(entity_name, False)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
||||||
lights.append(new_light)
|
lights.append(new_light)
|
||||||
@ -59,14 +60,15 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
if entity_id not in rfxtrx.RFX_DEVICES:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
automatic_add = config.get('automatic_add', False)
|
automatic_add = config.get('automatic_add', False)
|
||||||
if automatic_add:
|
if automatic_add:
|
||||||
logger.info("Automatic add %s rfxtrx.light" % entity_name)
|
_LOGGER.info("Automatic add %s rfxtrx.light", entity_id)
|
||||||
new_light = RfxtrxLight(entity_id, False)
|
new_light = RfxtrxLight(entity_id, False)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
||||||
add_devices_callback([new_light])
|
add_devices_callback([new_light])
|
||||||
|
|
||||||
# Check if entity exists (previous automatic added)
|
# Check if entity exists (previous automatic added)
|
||||||
if entity_id in rfxtrx.RFX_DEVICES:
|
if entity_id in rfxtrx.RFX_DEVICES:
|
||||||
if event.values['Command'] == 'On' or event.values['Command'] == 'Off':
|
if event.values['Command'] == 'On'\
|
||||||
|
or event.values['Command'] == 'Off':
|
||||||
if event.values['Command'] == 'On':
|
if event.values['Command'] == 'On':
|
||||||
rfxtrx.RFX_DEVICES[entity_id].turn_on()
|
rfxtrx.RFX_DEVICES[entity_id].turn_on()
|
||||||
else:
|
else:
|
||||||
@ -105,4 +107,4 @@ class RfxtrxLight(Light):
|
|||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
""" Turn the device off. """
|
""" Turn the device off. """
|
||||||
self._state = False
|
self._state = False
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
@ -14,13 +14,12 @@ DOMAIN = "rfxtrx"
|
|||||||
CONF_DEVICE = 'device'
|
CONF_DEVICE = 'device'
|
||||||
RECEIVED_EVT_SUBSCRIBERS = []
|
RECEIVED_EVT_SUBSCRIBERS = []
|
||||||
RFX_DEVICES = {}
|
RFX_DEVICES = {}
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Setup the Rfxtrx component. """
|
""" Setup the Rfxtrx component. """
|
||||||
|
|
||||||
# Init logger
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
# Declare the Handle event
|
# Declare the Handle event
|
||||||
def handle_receive(event):
|
def handle_receive(event):
|
||||||
""" Callback all subscribers for RFXtrx gateway. """
|
""" Callback all subscribers for RFXtrx gateway. """
|
||||||
@ -31,11 +30,11 @@ def setup(hass, config):
|
|||||||
try:
|
try:
|
||||||
import RFXtrx as rfxtrxmod
|
import RFXtrx as rfxtrxmod
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.exception("Failed to import rfxtrx")
|
_LOGGER.exception("Failed to import rfxtrx")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Init the rfxtrx module
|
# Init the rfxtrx module
|
||||||
device = config[DOMAIN][CONF_DEVICE]
|
device = config[DOMAIN][CONF_DEVICE]
|
||||||
rfxtrxmod.Core(device, handle_receive)
|
rfxtrxmod.Core(device, handle_receive)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -37,30 +37,32 @@ DATA_TYPES = OrderedDict([
|
|||||||
('Barometer', ''),
|
('Barometer', ''),
|
||||||
('Wind direction', ''),
|
('Wind direction', ''),
|
||||||
('Rain rate', '')])
|
('Rain rate', '')])
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Setup the RFXtrx platform. """
|
""" Setup the RFXtrx platform. """
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
sensors = {} # keep track of sensors added to HA
|
|
||||||
|
|
||||||
def sensor_update(event):
|
def sensor_update(event):
|
||||||
""" Callback for sensor updates from the RFXtrx gateway. """
|
""" Callback for sensor updates from the RFXtrx gateway. """
|
||||||
if isinstance(event.device, SensorEvent):
|
if isinstance(event.device, SensorEvent):
|
||||||
entity_id = '%s-%s' % (event.device.type_string.lower(), slugify(event.device.id_string.lower()))
|
entity_id = slugify(event.device.id_string.lower())
|
||||||
if entity_id in rfxtrx.RFX_DEVICES:
|
|
||||||
rfxtrx.RFX_DEVICES[entity_id].event = event
|
# Add entity if not exist and the automatic_add is True
|
||||||
else:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
automatic_add = config.get('automatic_add', False)
|
automatic_add = config.get('automatic_add', False)
|
||||||
if automatic_add:
|
if automatic_add:
|
||||||
new_light = RfxtrxSensor(entity_id, False)
|
_LOGGER.info("Automatic add %s rfxtrx.light", entity_id)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_light
|
new_sensor = RfxtrxSensor(event)
|
||||||
add_devices_callback([new_light])
|
rfxtrx.RFX_DEVICES[entity_id] = new_sensor
|
||||||
|
add_devices_callback([new_sensor])
|
||||||
|
else:
|
||||||
|
rfxtrx.RFX_DEVICES[entity_id].event = event
|
||||||
|
|
||||||
if sensor_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
|
if sensor_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
|
||||||
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(sensor_update)
|
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(sensor_update)
|
||||||
|
|
||||||
|
|
||||||
class RfxtrxSensor(Entity):
|
class RfxtrxSensor(Entity):
|
||||||
""" Represents a RFXtrx sensor. """
|
""" Represents a RFXtrx sensor. """
|
||||||
|
|
||||||
|
@ -33,17 +33,18 @@ REQUIREMENTS = ['https://github.com/Danielhiversen/pyRFXtrx/archive/' +
|
|||||||
'ec7a1aaddf8270db6e5da1c13d58c1547effd7cf.zip#RFXtrx==0.15']
|
'ec7a1aaddf8270db6e5da1c13d58c1547effd7cf.zip#RFXtrx==0.15']
|
||||||
|
|
||||||
DOMAIN = "rfxtrx"
|
DOMAIN = "rfxtrx"
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Setup the RFXtrx platform. """
|
""" Setup the RFXtrx platform. """
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
# Add switch from config file
|
# Add switch from config file
|
||||||
switchs = []
|
switchs = []
|
||||||
devices = config.get('devices')
|
devices = config.get('devices')
|
||||||
for entity_id, entity_name in devices.items():
|
for entity_id, entity_name in devices.items():
|
||||||
if entity_id not in rfxtrx.RFX_DEVICES:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
logger.info("Add %s rfxtrx.switch" % entity_name)
|
_LOGGER.info("Add %s rfxtrx.switch", entity_name)
|
||||||
new_switch = RfxtrxSwitch(entity_name, False)
|
new_switch = RfxtrxSwitch(entity_name, False)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_switch
|
rfxtrx.RFX_DEVICES[entity_id] = new_switch
|
||||||
switchs.append(new_switch)
|
switchs.append(new_switch)
|
||||||
@ -59,14 +60,15 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
if entity_id not in rfxtrx.RFX_DEVICES:
|
if entity_id not in rfxtrx.RFX_DEVICES:
|
||||||
automatic_add = config.get('automatic_add', False)
|
automatic_add = config.get('automatic_add', False)
|
||||||
if automatic_add:
|
if automatic_add:
|
||||||
logger.info("Automatic add %s rfxtrx.switch" % entity_name)
|
_LOGGER.info("Automatic add %s rfxtrx.switch", entity_id)
|
||||||
new_switch = RfxtrxSwitch(entity_id, False)
|
new_switch = RfxtrxSwitch(entity_id, False)
|
||||||
rfxtrx.RFX_DEVICES[entity_id] = new_switch
|
rfxtrx.RFX_DEVICES[entity_id] = new_switch
|
||||||
add_devices_callback([new_switch])
|
add_devices_callback([new_switch])
|
||||||
|
|
||||||
# Check if entity exists (previous automatic added)
|
# Check if entity exists (previous automatic added)
|
||||||
if entity_id in rfxtrx.RFX_DEVICES:
|
if entity_id in rfxtrx.RFX_DEVICES:
|
||||||
if event.values['Command'] == 'On' or event.values['Command'] == 'Off':
|
if event.values['Command'] == 'On'\
|
||||||
|
or event.values['Command'] == 'Off':
|
||||||
if event.values['Command'] == 'On':
|
if event.values['Command'] == 'On':
|
||||||
rfxtrx.RFX_DEVICES[entity_id].turn_on()
|
rfxtrx.RFX_DEVICES[entity_id].turn_on()
|
||||||
else:
|
else:
|
||||||
@ -105,4 +107,4 @@ class RfxtrxSwitch(SwitchDevice):
|
|||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
""" Turn the device off. """
|
""" Turn the device off. """
|
||||||
self._state = False
|
self._state = False
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user