Skip to content
Merged

0.108.2 #33932

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions homeassistant/components/bayesian/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ def device_class(self):
@property
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
print(self.current_observations)
print(self.observations_by_entity)
return {
ATTR_OBSERVATIONS: list(self.current_observations.values()),
ATTR_OCCURRED_OBSERVATION_ENTITIES: list(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/frontend/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "frontend",
"name": "Home Assistant Frontend",
"documentation": "https://www.home-assistant.io/integrations/frontend",
"requirements": ["home-assistant-frontend==20200407.1"],
"requirements": ["home-assistant-frontend==20200407.2"],
"dependencies": [
"api",
"auth",
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/ipp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ def device_state_attributes(self) -> Optional[Dict[str, Any]]:
@property
def state(self) -> Union[None, str, int, float]:
"""Return the state of the sensor."""
return self.coordinator.data.markers[self.marker_index].level
level = self.coordinator.data.markers[self.marker_index].level

if level >= 0:
return level

return None


class IPPPrinterSensor(IPPSensor):
Expand Down
11 changes: 5 additions & 6 deletions homeassistant/components/konnected/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,6 @@ async def async_step_user(self, user_input=None):
# build config info and wait for user confirmation
self.data[CONF_HOST] = user_input[CONF_HOST]
self.data[CONF_PORT] = user_input[CONF_PORT]
self.data[CONF_ACCESS_TOKEN] = self.hass.data.get(DOMAIN, {}).get(
CONF_ACCESS_TOKEN
) or "".join(
random.choices(f"{string.ascii_uppercase}{string.digits}", k=20)
)

# brief delay to allow processing of recent status req
await asyncio.sleep(0.1)
Expand Down Expand Up @@ -343,8 +338,12 @@ async def async_step_confirm(self, user_input=None):
},
)

# Attach default options and create entry
# Create access token, attach default options and create entry
self.data[CONF_DEFAULT_OPTIONS] = self.options
self.data[CONF_ACCESS_TOKEN] = self.hass.data.get(DOMAIN, {}).get(
CONF_ACCESS_TOKEN
) or "".join(random.choices(f"{string.ascii_uppercase}{string.digits}", k=20))

return self.async_create_entry(
title=KONN_PANEL_MODEL_NAMES[self.data[CONF_MODEL]], data=self.data,
)
Expand Down
48 changes: 20 additions & 28 deletions homeassistant/components/modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
CONF_PORT,
CONF_TIMEOUT,
CONF_TYPE,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
)
import homeassistant.helpers.config_validation as cv
Expand All @@ -36,7 +35,7 @@
CONF_PARITY,
CONF_STOPBITS,
DEFAULT_HUB,
MODBUS_DOMAIN,
MODBUS_DOMAIN as DOMAIN,
SERVICE_WRITE_COIL,
SERVICE_WRITE_REGISTER,
)
Expand Down Expand Up @@ -69,7 +68,7 @@
)

CONFIG_SCHEMA = vol.Schema(
{MODBUS_DOMAIN: vol.All(cv.ensure_list, [vol.Any(SERIAL_SCHEMA, ETHERNET_SCHEMA)])},
{DOMAIN: vol.All(cv.ensure_list, [vol.Any(SERIAL_SCHEMA, ETHERNET_SCHEMA)])},
extra=vol.ALLOW_EXTRA,
)

Expand All @@ -96,39 +95,23 @@

async def async_setup(hass, config):
"""Set up Modbus component."""
hass.data[MODBUS_DOMAIN] = hub_collect = {}
hass.data[DOMAIN] = hub_collect = {}

_LOGGER.debug("registering hubs")
for client_config in config[MODBUS_DOMAIN]:
for client_config in config[DOMAIN]:
hub_collect[client_config[CONF_NAME]] = ModbusHub(client_config, hass.loop)

def stop_modbus(event):
"""Stop Modbus service."""
for client in hub_collect.values():
del client

def start_modbus(event):
def start_modbus():
"""Start Modbus service."""
for client in hub_collect.values():
_LOGGER.debug("setup hub %s", client.name)
client.setup()

hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_modbus)

# Register services for modbus
hass.services.async_register(
MODBUS_DOMAIN,
SERVICE_WRITE_REGISTER,
write_register,
schema=SERVICE_WRITE_REGISTER_SCHEMA,
)
hass.services.async_register(
MODBUS_DOMAIN,
SERVICE_WRITE_COIL,
write_coil,
schema=SERVICE_WRITE_COIL_SCHEMA,
)

async def write_register(service):
"""Write Modbus registers."""
unit = int(float(service.data[ATTR_UNIT]))
Expand All @@ -152,8 +135,19 @@ async def write_coil(service):
client_name = service.data[ATTR_HUB]
await hub_collect[client_name].write_coil(unit, address, state)

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, start_modbus)

# do not wait for EVENT_HOMEASSISTANT_START, activate pymodbus now
await hass.async_add_executor_job(start_modbus)

# Register services for modbus
hass.services.async_register(
DOMAIN,
SERVICE_WRITE_REGISTER,
write_register,
schema=SERVICE_WRITE_REGISTER_SCHEMA,
)
hass.services.async_register(
DOMAIN, SERVICE_WRITE_COIL, write_coil, schema=SERVICE_WRITE_COIL_SCHEMA,
)
return True


Expand All @@ -162,7 +156,6 @@ class ModbusHub:

def __init__(self, client_config, main_loop):
"""Initialize the Modbus hub."""
_LOGGER.debug("Preparing setup: %s", client_config)

# generic configuration
self._loop = main_loop
Expand All @@ -172,7 +165,7 @@ def __init__(self, client_config, main_loop):
self._config_type = client_config[CONF_TYPE]
self._config_port = client_config[CONF_PORT]
self._config_timeout = client_config[CONF_TIMEOUT]
self._config_delay = client_config[CONF_DELAY]
self._config_delay = 0

if self._config_type == "serial":
# serial configuration
Expand All @@ -184,6 +177,7 @@ def __init__(self, client_config, main_loop):
else:
# network configuration
self._config_host = client_config[CONF_HOST]
self._config_delay = client_config[CONF_DELAY]

@property
def name(self):
Expand All @@ -201,7 +195,6 @@ def setup(self):
# Client* do deliver loop, client as result but
# pylint does not accept that fact

_LOGGER.debug("doing setup")
if self._config_type == "serial":
_, self._client = ClientSerial(
schedulers.ASYNC_IO,
Expand All @@ -211,7 +204,6 @@ def setup(self):
stopbits=self._config_stopbits,
bytesize=self._config_bytesize,
parity=self._config_parity,
timeout=self._config_timeout,
loop=self._loop,
)
elif self._config_type == "rtuovertcp":
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
)


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Modbus binary sensors."""
sensors = []
for entry in config[CONF_INPUTS]:
Expand All @@ -70,7 +70,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):
)
)

add_entities(sensors)
async_add_entities(sensors)


class ModbusBinarySensor(BinarySensorDevice):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
)


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Modbus Thermostat Platform."""
name = config[CONF_NAME]
modbus_slave = config[CONF_SLAVE]
Expand All @@ -91,7 +91,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):
hub_name = config[CONF_HUB]
hub = hass.data[MODBUS_DOMAIN][hub_name]

add_entities(
async_add_entities(
[
ModbusThermostat(
hub,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def number(value: Any) -> Union[int, float]:
)


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Modbus sensors."""
sensors = []
data_types = {DATA_TYPE_INT: {1: "h", 2: "i", 4: "q"}}
Expand Down Expand Up @@ -148,7 +148,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):

if not sensors:
return False
add_entities(sensors)
async_add_entities(sensors)


class ModbusRegisterSensor(RestoreEntity):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
)


async def async_setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Read configuration and create Modbus devices."""
switches = []
if CONF_COILS in config:
Expand Down Expand Up @@ -109,7 +109,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):
)
)

add_entities(switches)
async_add_entities(switches)


class ModbusCoilSwitch(ToggleEntity, RestoreEntity):
Expand Down
15 changes: 12 additions & 3 deletions homeassistant/components/monoprice/media_player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Support for interfacing with Monoprice 6 zone home audio controller."""
import logging

from serial import SerialException

from homeassistant import core
from homeassistant.components.media_player import MediaPlayerDevice
from homeassistant.components.media_player.const import (
Expand All @@ -18,6 +20,8 @@

_LOGGER = logging.getLogger(__name__)

PARALLEL_UPDATES = 1

SUPPORT_MONOPRICE = (
SUPPORT_VOLUME_MUTE
| SUPPORT_VOLUME_SET
Expand Down Expand Up @@ -127,9 +131,15 @@ def __init__(self, monoprice, sources, namespace, zone_id):

def update(self):
"""Retrieve latest state."""
state = self._monoprice.zone_status(self._zone_id)
try:
state = self._monoprice.zone_status(self._zone_id)
except SerialException:
_LOGGER.warning("Could not update zone %d", self._zone_id)
return

if not state:
return False
return

self._state = STATE_ON if state.power else STATE_OFF
self._volume = state.volume
self._mute = state.mute
Expand All @@ -138,7 +148,6 @@ def update(self):
self._source = self._source_id_name[idx]
else:
self._source = None
return True

@property
def entity_registry_enabled_default(self):
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/nextcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"nextcloud_storage_num_files",
"nextcloud_storage_num_storages",
"nextcloud_storage_num_storages_local",
"nextcloud_storage_num_storage_home",
"nextcloud_storage_num_storages_home",
"nextcloud_storage_num_storages_other",
"nextcloud_shares_num_shares",
"nextcloud_shares_num_shares_user",
Expand All @@ -83,9 +83,9 @@
"nextcloud_database_type",
"nextcloud_database_version",
"nextcloud_database_version",
"nextcloud_activeusers_last5minutes",
"nextcloud_activeusers_last1hour",
"nextcloud_activeusers_last24hours",
"nextcloud_activeUsers_last5minutes",
"nextcloud_activeUsers_last1hour",
"nextcloud_activeUsers_last24hours",
)


Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/onvif/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,17 @@ def fetch():
"""Read image from a URL."""
try:
response = requests.get(self._snapshot, timeout=5, auth=auth)
return response.content
if response.status_code < 300:
return response.content
except requests.exceptions.RequestException as error:
_LOGGER.error(
"Fetch snapshot image failed from %s, falling back to FFmpeg; %s",
self._name,
error,
)

return None

image = await self.hass.async_add_job(fetch)

if image is None:
Expand Down
Loading