Skip to content

Commit

Permalink
2022.10.4 (home-assistant#80343)
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob authored Oct 14, 2022
2 parents 1c74279 + e8c8a49 commit 68907b4
Show file tree
Hide file tree
Showing 51 changed files with 312 additions and 130 deletions.
5 changes: 3 additions & 2 deletions homeassistant/components/amcrest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
)
)
event_codes = {
sensor.event_code
event_code
for sensor in BINARY_SENSORS
if sensor.key in binary_sensors
and not sensor.should_poll
and sensor.event_code is not None
and sensor.event_codes is not None
for event_code in sensor.event_codes
}

_start_event_monitor(hass, name, api, event_codes)
Expand Down
50 changes: 25 additions & 25 deletions homeassistant/components/amcrest/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
class AmcrestSensorEntityDescription(BinarySensorEntityDescription):
"""Describe Amcrest sensor entity."""

event_code: str | None = None
event_codes: set[str] | None = None
should_poll: bool = False


Expand All @@ -51,7 +51,7 @@ class AmcrestSensorEntityDescription(BinarySensorEntityDescription):
_AUDIO_DETECTED_KEY = "audio_detected"
_AUDIO_DETECTED_POLLED_KEY = "audio_detected_polled"
_AUDIO_DETECTED_NAME = "Audio Detected"
_AUDIO_DETECTED_EVENT_CODE = "AudioMutation"
_AUDIO_DETECTED_EVENT_CODES = {"AudioMutation", "AudioIntensity"}

_CROSSLINE_DETECTED_KEY = "crossline_detected"
_CROSSLINE_DETECTED_POLLED_KEY = "crossline_detected_polled"
Expand All @@ -70,39 +70,39 @@ class AmcrestSensorEntityDescription(BinarySensorEntityDescription):
key=_AUDIO_DETECTED_KEY,
name=_AUDIO_DETECTED_NAME,
device_class=BinarySensorDeviceClass.SOUND,
event_code=_AUDIO_DETECTED_EVENT_CODE,
event_codes=_AUDIO_DETECTED_EVENT_CODES,
),
AmcrestSensorEntityDescription(
key=_AUDIO_DETECTED_POLLED_KEY,
name=_AUDIO_DETECTED_NAME,
device_class=BinarySensorDeviceClass.SOUND,
event_code=_AUDIO_DETECTED_EVENT_CODE,
event_codes=_AUDIO_DETECTED_EVENT_CODES,
should_poll=True,
),
AmcrestSensorEntityDescription(
key=_CROSSLINE_DETECTED_KEY,
name=_CROSSLINE_DETECTED_NAME,
device_class=BinarySensorDeviceClass.MOTION,
event_code=_CROSSLINE_DETECTED_EVENT_CODE,
event_codes={_CROSSLINE_DETECTED_EVENT_CODE},
),
AmcrestSensorEntityDescription(
key=_CROSSLINE_DETECTED_POLLED_KEY,
name=_CROSSLINE_DETECTED_NAME,
device_class=BinarySensorDeviceClass.MOTION,
event_code=_CROSSLINE_DETECTED_EVENT_CODE,
event_codes={_CROSSLINE_DETECTED_EVENT_CODE},
should_poll=True,
),
AmcrestSensorEntityDescription(
key=_MOTION_DETECTED_KEY,
name=_MOTION_DETECTED_NAME,
device_class=BinarySensorDeviceClass.MOTION,
event_code=_MOTION_DETECTED_EVENT_CODE,
event_codes={_MOTION_DETECTED_EVENT_CODE},
),
AmcrestSensorEntityDescription(
key=_MOTION_DETECTED_POLLED_KEY,
name=_MOTION_DETECTED_NAME,
device_class=BinarySensorDeviceClass.MOTION,
event_code=_MOTION_DETECTED_EVENT_CODE,
event_codes={_MOTION_DETECTED_EVENT_CODE},
should_poll=True,
),
AmcrestSensorEntityDescription(
Expand Down Expand Up @@ -211,13 +211,13 @@ async def _async_update_others(self) -> None:
log_update_error(_LOGGER, "update", self.name, "binary sensor", error)
return

if (event_code := self.entity_description.event_code) is None:
_LOGGER.error("Binary sensor %s event code not set", self.name)
return
if not (event_codes := self.entity_description.event_codes):
raise ValueError(f"Binary sensor {self.name} event codes not set")

try:
self._attr_is_on = (
self._attr_is_on = any( # type: ignore[arg-type]
len(await self._api.async_event_channels_happened(event_code)) > 0
for event_code in event_codes
)
except AmcrestError as error:
log_update_error(_LOGGER, "update", self.name, "binary sensor", error)
Expand Down Expand Up @@ -266,17 +266,17 @@ async def async_added_to_hass(self) -> None:
)

if (
self.entity_description.event_code
and not self.entity_description.should_poll
):
self.async_on_remove(
async_dispatcher_connect(
self.hass,
service_signal(
SERVICE_EVENT,
self._signal_name,
self.entity_description.event_code,
),
self.async_event_received,
event_codes := self.entity_description.event_codes
) and not self.entity_description.should_poll:
for event_code in event_codes:
self.async_on_remove(
async_dispatcher_connect(
self.hass,
service_signal(
SERVICE_EVENT,
self._signal_name,
event_code,
),
self.async_event_received,
)
)
)
2 changes: 1 addition & 1 deletion homeassistant/components/august/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "august",
"name": "August",
"documentation": "https://www.home-assistant.io/integrations/august",
"requirements": ["yalexs==1.2.4"],
"requirements": ["yalexs==1.2.6"],
"codeowners": ["@bdraco"],
"dhcp": [
{
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/esphome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "ESPHome",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/esphome",
"requirements": ["aioesphomeapi==11.1.0"],
"requirements": ["aioesphomeapi==11.1.1"],
"zeroconf": ["_esphomelib._tcp.local."],
"dhcp": [{ "registered_devices": true }],
"codeowners": ["@OttoWinter", "@jesserockz"],
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/homekit/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "HomeKit",
"documentation": "https://www.home-assistant.io/integrations/homekit",
"requirements": [
"HAP-python==4.5.0",
"ha-HAP-python==4.5.2",
"fnvhash==0.1.0",
"PyQRCode==1.2.1",
"base36==0.1.1"
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/mqtt/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
warn_for_legacy_schema,
)
from .models import MqttCommandTemplate, MqttValueTemplate
from .util import valid_publish_topic, valid_subscribe_topic
from .util import get_mqtt_data, valid_publish_topic, valid_subscribe_topic

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -211,7 +211,7 @@ def message_received(msg):
_LOGGER.warning("Received unexpected payload: %s", msg.payload)
return
self._state = payload
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

self._sub_state = subscription.async_prepare_subscribe_topics(
self.hass,
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/mqtt/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
warn_for_legacy_schema,
)
from .models import MqttValueTemplate
from .util import get_mqtt_data

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -260,7 +261,7 @@ def state_message_received(msg):
self.hass, off_delay, off_delay_listener
)

self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

self._sub_state = subscription.async_prepare_subscribe_topics(
self.hass,
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ def _mqtt_handle_message(self, msg: MQTTMessage) -> None:
timestamp,
),
)
self._mqtt_data.state_write_requests.process_write_state_requests()

def _mqtt_on_callback(self, _mqttc, _userdata, mid, _granted_qos=None) -> None:
"""Publish / Subscribe / Unsubscribe callback."""
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/mqtt/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
warn_for_legacy_schema,
)
from .models import MqttCommandTemplate, MqttValueTemplate
from .util import valid_publish_topic, valid_subscribe_topic
from .util import get_mqtt_data, valid_publish_topic, valid_subscribe_topic

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -494,7 +494,7 @@ def handle_action_received(msg):
payload,
)
return
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

add_subscription(topics, CONF_ACTION_TOPIC, handle_action_received)

Expand All @@ -505,7 +505,7 @@ def handle_temperature_received(msg, template_name, attr):

try:
setattr(self, attr, float(payload))
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
except ValueError:
_LOGGER.error("Could not parse temperature from %s", payload)

Expand Down Expand Up @@ -564,7 +564,7 @@ def handle_mode_received(msg, template_name, attr, mode_list):
_LOGGER.error("Invalid %s mode: %s", mode_list, payload)
else:
setattr(self, attr, payload)
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

@callback
@log_messages(self.hass, self.entity_id)
Expand Down Expand Up @@ -623,7 +623,7 @@ def handle_onoff_mode_received(msg, template_name, attr):
else:
_LOGGER.error("Invalid %s mode: %s", attr, payload)

self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

@callback
@log_messages(self.hass, self.entity_id)
Expand All @@ -640,7 +640,7 @@ def handle_preset_mode_received(msg):
preset_mode = render_template(msg, CONF_PRESET_MODE_VALUE_TEMPLATE)
if preset_mode in [PRESET_NONE, PAYLOAD_NONE]:
self._preset_mode = None
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
return
if not preset_mode:
_LOGGER.debug("Ignoring empty preset_mode from '%s'", msg.topic)
Expand All @@ -654,7 +654,7 @@ def handle_preset_mode_received(msg):
)
else:
self._preset_mode = preset_mode
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

add_subscription(
topics, CONF_PRESET_MODE_STATE_TOPIC, handle_preset_mode_received
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/mqtt/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
warn_for_legacy_schema,
)
from .models import MqttCommandTemplate, MqttValueTemplate
from .util import valid_publish_topic, valid_subscribe_topic
from .util import get_mqtt_data, valid_publish_topic, valid_subscribe_topic

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -405,7 +405,7 @@ def state_message_received(msg):
)
return

self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

@callback
@log_messages(self.hass, self.entity_id)
Expand Down Expand Up @@ -451,7 +451,7 @@ def position_message_received(msg):
else STATE_OPEN
)

self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

if self._config.get(CONF_GET_POSITION_TOPIC):
topics["get_position_topic"] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ..debug_info import log_messages
from ..mixins import MQTT_ENTITY_COMMON_SCHEMA, MqttEntity, async_setup_entry_helper
from ..models import MqttValueTemplate
from ..util import get_mqtt_data

CONF_PAYLOAD_HOME = "payload_home"
CONF_PAYLOAD_NOT_HOME = "payload_not_home"
Expand Down Expand Up @@ -106,7 +107,7 @@ def message_received(msg):
else:
self._location_name = msg.payload

self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

self._sub_state = subscription.async_prepare_subscribe_topics(
self.hass,
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/mqtt/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
warn_for_legacy_schema,
)
from .models import MqttCommandTemplate, MqttValueTemplate
from .util import valid_publish_topic, valid_subscribe_topic
from .util import get_mqtt_data, valid_publish_topic, valid_subscribe_topic

CONF_PERCENTAGE_STATE_TOPIC = "percentage_state_topic"
CONF_PERCENTAGE_COMMAND_TOPIC = "percentage_command_topic"
Expand Down Expand Up @@ -391,7 +391,7 @@ def state_received(msg):
self._state = False
elif payload == PAYLOAD_NONE:
self._state = None
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

if self._topic[CONF_STATE_TOPIC] is not None:
topics[CONF_STATE_TOPIC] = {
Expand All @@ -413,7 +413,7 @@ def percentage_received(msg):
return
if rendered_percentage_payload == self._payload["PERCENTAGE_RESET"]:
self._percentage = None
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
return
try:
percentage = ranged_value_to_percentage(
Expand All @@ -436,7 +436,7 @@ def percentage_received(msg):
)
return
self._percentage = percentage
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

if self._topic[CONF_PERCENTAGE_STATE_TOPIC] is not None:
topics[CONF_PERCENTAGE_STATE_TOPIC] = {
Expand Down Expand Up @@ -469,7 +469,7 @@ def preset_mode_received(msg):
return

self._preset_mode = preset_mode
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

if self._topic[CONF_PRESET_MODE_STATE_TOPIC] is not None:
topics[CONF_PRESET_MODE_STATE_TOPIC] = {
Expand All @@ -492,7 +492,7 @@ def oscillation_received(msg):
self._oscillation = True
elif payload == self._payload["OSCILLATE_OFF_PAYLOAD"]:
self._oscillation = False
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

if self._topic[CONF_OSCILLATION_STATE_TOPIC] is not None:
topics[CONF_OSCILLATION_STATE_TOPIC] = {
Expand Down
Loading

0 comments on commit 68907b4

Please sign in to comment.