Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -4,48 +4,59 @@ import logging
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_NAME, CONF_PIN, CONF_TOKEN, EVENT_HOMEASSISTANT_STOP)
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_PIN,
|
||||
CONF_TOKEN,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.helpers import discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = 'comfoconnect'
|
||||
DOMAIN = "comfoconnect"
|
||||
|
||||
SIGNAL_COMFOCONNECT_UPDATE_RECEIVED = 'comfoconnect_update_received'
|
||||
SIGNAL_COMFOCONNECT_UPDATE_RECEIVED = "comfoconnect_update_received"
|
||||
|
||||
ATTR_CURRENT_TEMPERATURE = 'current_temperature'
|
||||
ATTR_CURRENT_HUMIDITY = 'current_humidity'
|
||||
ATTR_OUTSIDE_TEMPERATURE = 'outside_temperature'
|
||||
ATTR_OUTSIDE_HUMIDITY = 'outside_humidity'
|
||||
ATTR_AIR_FLOW_SUPPLY = 'air_flow_supply'
|
||||
ATTR_AIR_FLOW_EXHAUST = 'air_flow_exhaust'
|
||||
ATTR_CURRENT_TEMPERATURE = "current_temperature"
|
||||
ATTR_CURRENT_HUMIDITY = "current_humidity"
|
||||
ATTR_OUTSIDE_TEMPERATURE = "outside_temperature"
|
||||
ATTR_OUTSIDE_HUMIDITY = "outside_humidity"
|
||||
ATTR_AIR_FLOW_SUPPLY = "air_flow_supply"
|
||||
ATTR_AIR_FLOW_EXHAUST = "air_flow_exhaust"
|
||||
|
||||
CONF_USER_AGENT = 'user_agent'
|
||||
CONF_USER_AGENT = "user_agent"
|
||||
|
||||
DEFAULT_NAME = 'ComfoAirQ'
|
||||
DEFAULT_NAME = "ComfoAirQ"
|
||||
DEFAULT_PIN = 0
|
||||
DEFAULT_TOKEN = '00000000000000000000000000000001'
|
||||
DEFAULT_USER_AGENT = 'Home Assistant'
|
||||
DEFAULT_TOKEN = "00000000000000000000000000000001"
|
||||
DEFAULT_USER_AGENT = "Home Assistant"
|
||||
|
||||
DEVICE = None
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_TOKEN, default=DEFAULT_TOKEN):
|
||||
vol.Length(min=32, max=32, msg='invalid token'),
|
||||
vol.Optional(CONF_USER_AGENT, default=DEFAULT_USER_AGENT): cv.string,
|
||||
vol.Optional(CONF_PIN, default=DEFAULT_PIN): cv.positive_int,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_TOKEN, default=DEFAULT_TOKEN): vol.Length(
|
||||
min=32, max=32, msg="invalid token"
|
||||
),
|
||||
vol.Optional(CONF_USER_AGENT, default=DEFAULT_USER_AGENT): cv.string,
|
||||
vol.Optional(CONF_PIN, default=DEFAULT_PIN): cv.positive_int,
|
||||
}
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the ComfoConnect bridge."""
|
||||
from pycomfoconnect import (Bridge)
|
||||
from pycomfoconnect import Bridge
|
||||
|
||||
conf = config[DOMAIN]
|
||||
host = conf.get(CONF_HOST)
|
||||
@@ -76,7 +87,7 @@ def setup(hass, config):
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown)
|
||||
|
||||
# Load platforms
|
||||
discovery.load_platform(hass, 'fan', DOMAIN, {}, config)
|
||||
discovery.load_platform(hass, "fan", DOMAIN, {}, config)
|
||||
|
||||
return True
|
||||
|
||||
@@ -86,15 +97,18 @@ class ComfoConnectBridge:
|
||||
|
||||
def __init__(self, hass, bridge, name, token, friendly_name, pin):
|
||||
"""Initialize the ComfoConnect bridge."""
|
||||
from pycomfoconnect import (ComfoConnect)
|
||||
from pycomfoconnect import ComfoConnect
|
||||
|
||||
self.data = {}
|
||||
self.name = name
|
||||
self.hass = hass
|
||||
|
||||
self.comfoconnect = ComfoConnect(
|
||||
bridge=bridge, local_uuid=bytes.fromhex(token),
|
||||
local_devicename=friendly_name, pin=pin)
|
||||
bridge=bridge,
|
||||
local_uuid=bytes.fromhex(token),
|
||||
local_devicename=friendly_name,
|
||||
pin=pin,
|
||||
)
|
||||
self.comfoconnect.callback_sensor = self.sensor_callback
|
||||
|
||||
def connect(self):
|
||||
@@ -112,7 +126,9 @@ class ComfoConnectBridge:
|
||||
_LOGGER.debug("Got value from bridge: %d = %d", var, value)
|
||||
|
||||
from pycomfoconnect import (
|
||||
SENSOR_TEMPERATURE_EXTRACT, SENSOR_TEMPERATURE_OUTDOOR)
|
||||
SENSOR_TEMPERATURE_EXTRACT,
|
||||
SENSOR_TEMPERATURE_OUTDOOR,
|
||||
)
|
||||
|
||||
if var in [SENSOR_TEMPERATURE_EXTRACT, SENSOR_TEMPERATURE_OUTDOOR]:
|
||||
self.data[var] = value / 10
|
||||
|
||||
@@ -2,20 +2,20 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.components.fan import (
|
||||
SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM, SPEED_OFF, SUPPORT_SET_SPEED,
|
||||
FanEntity)
|
||||
SPEED_HIGH,
|
||||
SPEED_LOW,
|
||||
SPEED_MEDIUM,
|
||||
SPEED_OFF,
|
||||
SUPPORT_SET_SPEED,
|
||||
FanEntity,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import dispatcher_connect
|
||||
|
||||
from . import DOMAIN, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, ComfoConnectBridge
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SPEED_MAPPING = {
|
||||
0: SPEED_OFF,
|
||||
1: SPEED_LOW,
|
||||
2: SPEED_MEDIUM,
|
||||
3: SPEED_HIGH
|
||||
}
|
||||
SPEED_MAPPING = {0: SPEED_OFF, 1: SPEED_LOW, 2: SPEED_MEDIUM, 3: SPEED_HIGH}
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
@@ -44,8 +44,7 @@ class ComfoConnectFan(FanEntity):
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
# Register for dispatcher updates
|
||||
dispatcher_connect(
|
||||
hass, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, _handle_update)
|
||||
dispatcher_connect(hass, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, _handle_update)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -55,7 +54,7 @@ class ComfoConnectFan(FanEntity):
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend."""
|
||||
return 'mdi:air-conditioner'
|
||||
return "mdi:air-conditioner"
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
@@ -65,7 +64,7 @@ class ComfoConnectFan(FanEntity):
|
||||
@property
|
||||
def speed(self):
|
||||
"""Return the current fan mode."""
|
||||
from pycomfoconnect import (SENSOR_FAN_SPEED_MODE)
|
||||
from pycomfoconnect import SENSOR_FAN_SPEED_MODE
|
||||
|
||||
try:
|
||||
speed = self._ccb.data[SENSOR_FAN_SPEED_MODE]
|
||||
@@ -90,11 +89,14 @@ class ComfoConnectFan(FanEntity):
|
||||
|
||||
def set_speed(self, speed: str):
|
||||
"""Set fan speed."""
|
||||
_LOGGER.debug('Changing fan speed to %s.', speed)
|
||||
_LOGGER.debug("Changing fan speed to %s.", speed)
|
||||
|
||||
from pycomfoconnect import (
|
||||
CMD_FAN_MODE_AWAY, CMD_FAN_MODE_LOW, CMD_FAN_MODE_MEDIUM,
|
||||
CMD_FAN_MODE_HIGH)
|
||||
CMD_FAN_MODE_AWAY,
|
||||
CMD_FAN_MODE_LOW,
|
||||
CMD_FAN_MODE_MEDIUM,
|
||||
CMD_FAN_MODE_HIGH,
|
||||
)
|
||||
|
||||
if speed == SPEED_OFF:
|
||||
self._ccb.comfoconnect.cmd_rmi_request(CMD_FAN_MODE_AWAY)
|
||||
|
||||
@@ -6,9 +6,16 @@ from homeassistant.helpers.dispatcher import dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import (
|
||||
ATTR_AIR_FLOW_EXHAUST, ATTR_AIR_FLOW_SUPPLY, ATTR_CURRENT_HUMIDITY,
|
||||
ATTR_CURRENT_TEMPERATURE, ATTR_OUTSIDE_HUMIDITY, ATTR_OUTSIDE_TEMPERATURE,
|
||||
DOMAIN, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, ComfoConnectBridge)
|
||||
ATTR_AIR_FLOW_EXHAUST,
|
||||
ATTR_AIR_FLOW_SUPPLY,
|
||||
ATTR_CURRENT_HUMIDITY,
|
||||
ATTR_CURRENT_TEMPERATURE,
|
||||
ATTR_OUTSIDE_HUMIDITY,
|
||||
ATTR_OUTSIDE_TEMPERATURE,
|
||||
DOMAIN,
|
||||
SIGNAL_COMFOCONNECT_UPDATE_RECEIVED,
|
||||
ComfoConnectBridge,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -18,47 +25,51 @@ SENSOR_TYPES = {}
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the ComfoConnect fan platform."""
|
||||
from pycomfoconnect import (
|
||||
SENSOR_TEMPERATURE_EXTRACT, SENSOR_HUMIDITY_EXTRACT,
|
||||
SENSOR_TEMPERATURE_OUTDOOR, SENSOR_HUMIDITY_OUTDOOR,
|
||||
SENSOR_FAN_SUPPLY_FLOW, SENSOR_FAN_EXHAUST_FLOW)
|
||||
SENSOR_TEMPERATURE_EXTRACT,
|
||||
SENSOR_HUMIDITY_EXTRACT,
|
||||
SENSOR_TEMPERATURE_OUTDOOR,
|
||||
SENSOR_HUMIDITY_OUTDOOR,
|
||||
SENSOR_FAN_SUPPLY_FLOW,
|
||||
SENSOR_FAN_EXHAUST_FLOW,
|
||||
)
|
||||
|
||||
global SENSOR_TYPES
|
||||
SENSOR_TYPES = {
|
||||
ATTR_CURRENT_TEMPERATURE: [
|
||||
'Inside Temperature',
|
||||
"Inside Temperature",
|
||||
TEMP_CELSIUS,
|
||||
'mdi:thermometer',
|
||||
SENSOR_TEMPERATURE_EXTRACT
|
||||
"mdi:thermometer",
|
||||
SENSOR_TEMPERATURE_EXTRACT,
|
||||
],
|
||||
ATTR_CURRENT_HUMIDITY: [
|
||||
'Inside Humidity',
|
||||
'%',
|
||||
'mdi:water-percent',
|
||||
SENSOR_HUMIDITY_EXTRACT
|
||||
"Inside Humidity",
|
||||
"%",
|
||||
"mdi:water-percent",
|
||||
SENSOR_HUMIDITY_EXTRACT,
|
||||
],
|
||||
ATTR_OUTSIDE_TEMPERATURE: [
|
||||
'Outside Temperature',
|
||||
"Outside Temperature",
|
||||
TEMP_CELSIUS,
|
||||
'mdi:thermometer',
|
||||
SENSOR_TEMPERATURE_OUTDOOR
|
||||
"mdi:thermometer",
|
||||
SENSOR_TEMPERATURE_OUTDOOR,
|
||||
],
|
||||
ATTR_OUTSIDE_HUMIDITY: [
|
||||
'Outside Humidity',
|
||||
'%',
|
||||
'mdi:water-percent',
|
||||
SENSOR_HUMIDITY_OUTDOOR
|
||||
"Outside Humidity",
|
||||
"%",
|
||||
"mdi:water-percent",
|
||||
SENSOR_HUMIDITY_OUTDOOR,
|
||||
],
|
||||
ATTR_AIR_FLOW_SUPPLY: [
|
||||
'Supply airflow',
|
||||
'm³/h',
|
||||
'mdi:air-conditioner',
|
||||
SENSOR_FAN_SUPPLY_FLOW
|
||||
"Supply airflow",
|
||||
"m³/h",
|
||||
"mdi:air-conditioner",
|
||||
SENSOR_FAN_SUPPLY_FLOW,
|
||||
],
|
||||
ATTR_AIR_FLOW_EXHAUST: [
|
||||
'Exhaust airflow',
|
||||
'm³/h',
|
||||
'mdi:air-conditioner',
|
||||
SENSOR_FAN_EXHAUST_FLOW
|
||||
"Exhaust airflow",
|
||||
"m³/h",
|
||||
"mdi:air-conditioner",
|
||||
SENSOR_FAN_EXHAUST_FLOW,
|
||||
],
|
||||
}
|
||||
|
||||
@@ -69,8 +80,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
sensor_type = resource.lower()
|
||||
|
||||
if sensor_type not in SENSOR_TYPES:
|
||||
_LOGGER.warning("Sensor type: %s is not a valid sensor.",
|
||||
sensor_type)
|
||||
_LOGGER.warning("Sensor type: %s is not a valid sensor.", sensor_type)
|
||||
continue
|
||||
|
||||
sensors.append(
|
||||
@@ -78,7 +88,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
hass,
|
||||
name="%s %s" % (ccb.name, SENSOR_TYPES[sensor_type][0]),
|
||||
ccb=ccb,
|
||||
sensor_type=sensor_type
|
||||
sensor_type=sensor_type,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -88,8 +98,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
class ComfoConnectSensor(Entity):
|
||||
"""Representation of a ComfoConnect sensor."""
|
||||
|
||||
def __init__(self, hass, name, ccb: ComfoConnectBridge,
|
||||
sensor_type) -> None:
|
||||
def __init__(self, hass, name, ccb: ComfoConnectBridge, sensor_type) -> None:
|
||||
"""Initialize the ComfoConnect sensor."""
|
||||
self._ccb = ccb
|
||||
self._sensor_type = sensor_type
|
||||
@@ -101,12 +110,11 @@ class ComfoConnectSensor(Entity):
|
||||
|
||||
def _handle_update(var):
|
||||
if var == self._sensor_id:
|
||||
_LOGGER.debug('Dispatcher update for %s.', var)
|
||||
_LOGGER.debug("Dispatcher update for %s.", var)
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
# Register for dispatcher updates
|
||||
dispatcher_connect(
|
||||
hass, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, _handle_update)
|
||||
dispatcher_connect(hass, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, _handle_update)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
||||
Reference in new issue
Block a user