Remove global variable from arduino (#33718)
* Remove global variable from arduino * Run isort
This commit is contained in:
parent
983ed8b8b4
commit
40ce8f8c9c
3 changed files with 27 additions and 21 deletions
|
@ -14,8 +14,6 @@ import homeassistant.helpers.config_validation as cv
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
BOARD = None
|
||||
|
||||
DOMAIN = "arduino"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
|
@ -28,15 +26,15 @@ def setup(hass, config):
|
|||
|
||||
port = config[DOMAIN][CONF_PORT]
|
||||
|
||||
global BOARD # pylint: disable=global-statement
|
||||
board = None
|
||||
try:
|
||||
BOARD = ArduinoBoard(port)
|
||||
board = ArduinoBoard(port)
|
||||
except (serial.serialutil.SerialException, FileNotFoundError):
|
||||
_LOGGER.error("Your port %s is not accessible", port)
|
||||
return False
|
||||
|
||||
try:
|
||||
if BOARD.get_firmata()[1] <= 2:
|
||||
if board.get_firmata()[1] <= 2:
|
||||
_LOGGER.error("The StandardFirmata sketch should be 2.2 or newer")
|
||||
return False
|
||||
except IndexError:
|
||||
|
@ -47,13 +45,14 @@ def setup(hass, config):
|
|||
|
||||
def stop_arduino(event):
|
||||
"""Stop the Arduino service."""
|
||||
BOARD.disconnect()
|
||||
board.disconnect()
|
||||
|
||||
def start_arduino(event):
|
||||
"""Start the Arduino service."""
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_arduino)
|
||||
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_arduino)
|
||||
hass.data[DOMAIN] = board
|
||||
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue