1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -3,8 +3,7 @@ import logging
import voluptuous as vol
from homeassistant.const import (
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
from homeassistant.const import CONF_PORT
import homeassistant.helpers.config_validation as cv
@@ -12,13 +11,11 @@ _LOGGER = logging.getLogger(__name__)
BOARD = None
DOMAIN = 'arduino'
DOMAIN = "arduino"
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_PORT): cv.string,
}),
}, extra=vol.ALLOW_EXTRA)
CONFIG_SCHEMA = vol.Schema(
{DOMAIN: vol.Schema({vol.Required(CONF_PORT): cv.string})}, extra=vol.ALLOW_EXTRA
)
def setup(hass, config):
@@ -39,8 +36,10 @@ def setup(hass, config):
_LOGGER.error("The StandardFirmata sketch should be 2.2 or newer")
return False
except IndexError:
_LOGGER.warning("The version of the StandardFirmata sketch was not"
"detected. This may lead to side effects")
_LOGGER.warning(
"The version of the StandardFirmata sketch was not"
"detected. This may lead to side effects"
)
def stop_arduino(event):
"""Stop the Arduino service."""
@@ -61,26 +60,22 @@ class ArduinoBoard:
def __init__(self, port):
"""Initialize the board."""
from PyMata.pymata import PyMata
self._port = port
self._board = PyMata(self._port, verbose=False)
def set_mode(self, pin, direction, mode):
"""Set the mode and the direction of a given pin."""
if mode == 'analog' and direction == 'in':
self._board.set_pin_mode(
pin, self._board.INPUT, self._board.ANALOG)
elif mode == 'analog' and direction == 'out':
self._board.set_pin_mode(
pin, self._board.OUTPUT, self._board.ANALOG)
elif mode == 'digital' and direction == 'in':
self._board.set_pin_mode(
pin, self._board.INPUT, self._board.DIGITAL)
elif mode == 'digital' and direction == 'out':
self._board.set_pin_mode(
pin, self._board.OUTPUT, self._board.DIGITAL)
elif mode == 'pwm':
self._board.set_pin_mode(
pin, self._board.OUTPUT, self._board.PWM)
if mode == "analog" and direction == "in":
self._board.set_pin_mode(pin, self._board.INPUT, self._board.ANALOG)
elif mode == "analog" and direction == "out":
self._board.set_pin_mode(pin, self._board.OUTPUT, self._board.ANALOG)
elif mode == "digital" and direction == "in":
self._board.set_pin_mode(pin, self._board.INPUT, self._board.DIGITAL)
elif mode == "digital" and direction == "out":
self._board.set_pin_mode(pin, self._board.OUTPUT, self._board.DIGITAL)
elif mode == "pwm":
self._board.set_pin_mode(pin, self._board.OUTPUT, self._board.PWM)
def get_analog_inputs(self):
"""Get the values from the pins."""

View File

@@ -11,17 +11,14 @@ import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
CONF_PINS = 'pins'
CONF_TYPE = 'analog'
CONF_PINS = "pins"
CONF_TYPE = "analog"
PIN_SCHEMA = vol.Schema({
vol.Required(CONF_NAME): cv.string,
})
PIN_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_PINS):
vol.Schema({cv.positive_int: PIN_SCHEMA}),
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Required(CONF_PINS): vol.Schema({cv.positive_int: PIN_SCHEMA})}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
@@ -46,7 +43,7 @@ class ArduinoSensor(Entity):
self._pin = pin
self._name = name
self.pin_type = pin_type
self.direction = 'in'
self.direction = "in"
self._value = None
arduino.BOARD.set_mode(self._pin, self.direction, self.pin_type)

View File

@@ -4,27 +4,28 @@ import logging
import voluptuous as vol
from homeassistant.components import arduino
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
CONF_PINS = 'pins'
CONF_TYPE = 'digital'
CONF_NEGATE = 'negate'
CONF_INITIAL = 'initial'
CONF_PINS = "pins"
CONF_TYPE = "digital"
CONF_NEGATE = "negate"
CONF_INITIAL = "initial"
PIN_SCHEMA = vol.Schema({
vol.Required(CONF_NAME): cv.string,
vol.Optional(CONF_INITIAL, default=False): cv.boolean,
vol.Optional(CONF_NEGATE, default=False): cv.boolean,
})
PIN_SCHEMA = vol.Schema(
{
vol.Required(CONF_NAME): cv.string,
vol.Optional(CONF_INITIAL, default=False): cv.boolean,
vol.Optional(CONF_NEGATE, default=False): cv.boolean,
}
)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_PINS, default={}):
vol.Schema({cv.positive_int: PIN_SCHEMA}),
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Required(CONF_PINS, default={}): vol.Schema({cv.positive_int: PIN_SCHEMA})}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
@@ -50,7 +51,7 @@ class ArduinoSwitch(SwitchDevice):
self._pin = pin
self._name = options.get(CONF_NAME)
self.pin_type = CONF_TYPE
self.direction = 'out'
self.direction = "out"
self._state = options.get(CONF_INITIAL)