Skip to content

Commit

Permalink
Merge branch 'dev' into modbus-nan-values
Browse files Browse the repository at this point in the history
  • Loading branch information
joanwa committed Apr 8, 2023
2 parents f5d02d5 + 6c7f216 commit a739f18
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 44 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/androidtv_remote/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"iot_class": "local_push",
"loggers": ["androidtvremote2"],
"quality_scale": "platinum",
"requirements": ["androidtvremote2==0.0.5"],
"requirements": ["androidtvremote2==0.0.7"],
"zeroconf": ["_androidtvremote2._tcp.local."]
}
63 changes: 45 additions & 18 deletions homeassistant/components/filter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@
NAME_TEMPLATE = "{} filter"
ICON = "mdi:chart-line-variant"

FILTER_SCHEMA = vol.Schema(
{vol.Optional(CONF_FILTER_PRECISION, default=DEFAULT_PRECISION): vol.Coerce(int)}
)
FILTER_SCHEMA = vol.Schema({vol.Optional(CONF_FILTER_PRECISION): vol.Coerce(int)})

FILTER_OUTLIER_SCHEMA = FILTER_SCHEMA.extend(
{
Expand Down Expand Up @@ -383,9 +381,9 @@ def __init__(self, state: _State) -> None:
except ValueError:
self.state = state.state

def set_precision(self, precision: int) -> None:
def set_precision(self, precision: int | None) -> None:
"""Set precision of Number based states."""
if isinstance(self.state, Number):
if precision is not None and isinstance(self.state, Number):
value = round(float(self.state), precision)
self.state = int(value) if precision == 0 else value

Expand Down Expand Up @@ -417,8 +415,8 @@ def __init__(
self,
name: str,
window_size: int | timedelta,
precision: int,
entity: str,
precision: int | None,
) -> None:
"""Initialize common attributes.
Expand Down Expand Up @@ -467,6 +465,7 @@ def filter_state(self, new_state: _State) -> _State:

filtered = self._filter_state(fstate)
filtered.set_precision(self.filter_precision)

if self._store_raw:
self.states.append(copy(FilterState(new_state)))
else:
Expand All @@ -485,8 +484,9 @@ class RangeFilter(Filter, SensorEntity):

def __init__(
self,
*,
entity: str,
precision: int,
precision: int | None = None,
lower_bound: float | None = None,
upper_bound: float | None = None,
) -> None:
Expand All @@ -495,7 +495,9 @@ def __init__(
:param upper_bound: band upper bound
:param lower_bound: band lower bound
"""
super().__init__(FILTER_NAME_RANGE, DEFAULT_WINDOW_SIZE, precision, entity)
super().__init__(
FILTER_NAME_RANGE, DEFAULT_WINDOW_SIZE, precision=precision, entity=entity
)
self._lower_bound = lower_bound
self._upper_bound = upper_bound
self._stats_internal: Counter = Counter()
Expand Down Expand Up @@ -539,13 +541,20 @@ class OutlierFilter(Filter, SensorEntity):
"""

def __init__(
self, window_size: int, precision: int, entity: str, radius: float
self,
*,
window_size: int,
entity: str,
radius: float,
precision: int | None = None,
) -> None:
"""Initialize Filter.
:param radius: band radius
"""
super().__init__(FILTER_NAME_OUTLIER, window_size, precision, entity)
super().__init__(
FILTER_NAME_OUTLIER, window_size, precision=precision, entity=entity
)
self._radius = radius
self._stats_internal: Counter = Counter()
self._store_raw = True
Expand Down Expand Up @@ -579,10 +588,17 @@ class LowPassFilter(Filter, SensorEntity):
"""BASIC Low Pass Filter."""

def __init__(
self, window_size: int, precision: int, entity: str, time_constant: int
self,
*,
window_size: int,
entity: str,
time_constant: int,
precision: int = DEFAULT_PRECISION,
) -> None:
"""Initialize Filter."""
super().__init__(FILTER_NAME_LOWPASS, window_size, precision, entity)
super().__init__(
FILTER_NAME_LOWPASS, window_size, precision=precision, entity=entity
)
self._time_constant = time_constant

def _filter_state(self, new_state: FilterState) -> FilterState:
Expand Down Expand Up @@ -610,16 +626,19 @@ class TimeSMAFilter(Filter, SensorEntity):

def __init__(
self,
*,
window_size: timedelta,
precision: int,
entity: str,
type: str, # pylint: disable=redefined-builtin
precision: int = DEFAULT_PRECISION,
) -> None:
"""Initialize Filter.
:param type: type of algorithm used to connect discrete values
"""
super().__init__(FILTER_NAME_TIME_SMA, window_size, precision, entity)
super().__init__(
FILTER_NAME_TIME_SMA, window_size, precision=precision, entity=entity
)
self._time_window = window_size
self.last_leak: FilterState | None = None
self.queue = deque[FilterState]()
Expand Down Expand Up @@ -660,9 +679,13 @@ class ThrottleFilter(Filter, SensorEntity):
One sample per window.
"""

def __init__(self, window_size: int, precision: int, entity: str) -> None:
def __init__(
self, *, window_size: int, entity: str, precision: None = None
) -> None:
"""Initialize Filter."""
super().__init__(FILTER_NAME_THROTTLE, window_size, precision, entity)
super().__init__(
FILTER_NAME_THROTTLE, window_size, precision=precision, entity=entity
)
self._only_numbers = False

def _filter_state(self, new_state: FilterState) -> FilterState:
Expand All @@ -683,9 +706,13 @@ class TimeThrottleFilter(Filter, SensorEntity):
One sample per time period.
"""

def __init__(self, window_size: timedelta, precision: int, entity: str) -> None:
def __init__(
self, *, window_size: timedelta, entity: str, precision: int | None = None
) -> None:
"""Initialize Filter."""
super().__init__(FILTER_NAME_TIME_THROTTLE, window_size, precision, entity)
super().__init__(
FILTER_NAME_TIME_THROTTLE, window_size, precision=precision, entity=entity
)
self._time_window = window_size
self._last_emitted_at: datetime | None = None
self._only_numbers = False
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/calendar.google/",
"iot_class": "cloud_polling",
"loggers": ["googleapiclient"],
"requirements": ["gcal-sync==4.1.3", "oauth2client==4.1.3"]
"requirements": ["gcal-sync==4.1.4", "oauth2client==4.1.3"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/roomba/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"documentation": "https://www.home-assistant.io/integrations/roomba",
"iot_class": "local_push",
"loggers": ["paho_mqtt", "roombapy"],
"requirements": ["roombapy==1.6.6"]
"requirements": ["roombapy==1.6.8"]
}
39 changes: 37 additions & 2 deletions homeassistant/components/sql/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import TemplateError
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down Expand Up @@ -153,10 +154,44 @@ async def async_setup_sensor(
):
return

upper_query = query_str.upper()
if use_database_executor:
redacted_query = redact_credentials(query_str)

issue_key = unique_id if unique_id else redacted_query
# If the query has a unique id and they fix it we can dismiss the issue
# but if it doesn't have a unique id they have to ignore it instead

if "ENTITY_ID" in upper_query and "STATES_META" not in upper_query:
_LOGGER.error(
"The query `%s` contains the keyword `entity_id` but does not "
"reference the `states_meta` table. This will cause a full table "
"scan and database instability. Please check the documentation and use "
"`states_meta.entity_id` instead",
redacted_query,
)

ir.async_create_issue(
hass,
DOMAIN,
f"entity_id_query_does_full_table_scan_{issue_key}",
translation_key="entity_id_query_does_full_table_scan",
translation_placeholders={"query": redacted_query},
is_fixable=False,
severity=ir.IssueSeverity.ERROR,
)
raise ValueError(
"Query contains entity_id but does not reference states_meta"
)

ir.async_delete_issue(
hass, DOMAIN, f"entity_id_query_does_full_table_scan_{issue_key}"
)

# MSSQL uses TOP and not LIMIT
if not ("LIMIT" in query_str.upper() or "SELECT TOP" in query_str.upper()):
if not ("LIMIT" in upper_query or "SELECT TOP" in upper_query):
if "mssql" in db_url:
query_str = query_str.upper().replace("SELECT", "SELECT TOP 1")
query_str = upper_query.replace("SELECT", "SELECT TOP 1")
else:
query_str = query_str.replace(";", "") + " LIMIT 1;"

Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/sql/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@
"db_url_invalid": "[%key:component::sql::config::error::db_url_invalid%]",
"query_invalid": "[%key:component::sql::config::error::query_invalid%]"
}
},
"issues": {
"entity_id_query_does_full_table_scan": {
"title": "SQL query does full table scan",
"description": "The query `{query}` contains the keyword `entity_id` but does not reference the `states_meta` table. This will cause a full table scan and database instability. Please check the documentation and use `states_meta.entity_id` instead."
}
}
}
2 changes: 1 addition & 1 deletion homeassistant/components/subaru/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/subaru",
"iot_class": "cloud_polling",
"loggers": ["stdiomask", "subarulink"],
"requirements": ["subarulink==0.7.5"]
"requirements": ["subarulink==0.7.6"]
}
6 changes: 6 additions & 0 deletions homeassistant/components/upnp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
},
{
"st": "urn:schemas-upnp-org:device:InternetGatewayDevice:2"
},
{
"nt": "urn:schemas-upnp-org:device:InternetGatewayDevice:1"
},
{
"nt": "urn:schemas-upnp-org:device:InternetGatewayDevice:2"
}
]
}
2 changes: 1 addition & 1 deletion homeassistant/components/zeroconf/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_push",
"loggers": ["zeroconf"],
"quality_scale": "internal",
"requirements": ["zeroconf==0.55.0"]
"requirements": ["zeroconf==0.56.0"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,16 @@ class SmartThingsAcceleration(ZigbeeChannel):
@callback
def attribute_updated(self, attrid, value):
"""Handle attribute updates on this cluster."""
try:
attr_name = self._cluster.attributes[attrid].name
except KeyError:
attr_name = UNKNOWN

if attrid == self.value_attribute:
self.async_send_signal(
f"{self.unique_id}_{SIGNAL_ATTR_UPDATED}",
attrid,
self._cluster.attributes.get(attrid, [UNKNOWN])[0],
attr_name,
value,
)
return
Expand All @@ -200,7 +205,7 @@ def attribute_updated(self, attrid, value):
SIGNAL_ATTR_UPDATED,
{
ATTR_ATTRIBUTE_ID: attrid,
ATTR_ATTRIBUTE_NAME: self._cluster.attributes.get(attrid, [UNKNOWN])[0],
ATTR_ATTRIBUTE_NAME: attr_name,
ATTR_VALUE: value,
},
)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zha/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"bellows==0.35.0",
"pyserial==3.5",
"pyserial-asyncio==0.6",
"zha-quirks==0.0.95",
"zha-quirks==0.0.96",
"zigpy-deconz==0.20.0",
"zigpy==0.54.0",
"zigpy-xbee==0.17.0",
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/generated/ssdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@
{
"st": "urn:schemas-upnp-org:device:InternetGatewayDevice:2",
},
{
"nt": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
},
{
"nt": "urn:schemas-upnp-org:device:InternetGatewayDevice:2",
},
],
"webostv": [
{
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ulid-transform==0.6.0
voluptuous-serialize==2.6.0
voluptuous==0.13.1
yarl==1.8.1
zeroconf==0.55.0
zeroconf==0.56.0

# Constrain pycryptodome to avoid vulnerability
# see https://github.com/home-assistant/core/pull/16238
Expand Down
12 changes: 6 additions & 6 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ amcrest==1.9.7
androidtv[async]==0.0.70

# homeassistant.components.androidtv_remote
androidtvremote2==0.0.5
androidtvremote2==0.0.7

# homeassistant.components.anel_pwrctrl
anel_pwrctrl-homeassistant==0.0.1.dev2
Expand Down Expand Up @@ -757,7 +757,7 @@ gTTS==2.2.4
gassist-text==0.0.10

# homeassistant.components.google
gcal-sync==4.1.3
gcal-sync==4.1.4

# homeassistant.components.geniushub
geniushub-client==0.7.0
Expand Down Expand Up @@ -2258,7 +2258,7 @@ rocketchat-API==0.6.1
rokuecp==0.17.1

# homeassistant.components.roomba
roombapy==1.6.6
roombapy==1.6.8

# homeassistant.components.roon
roonapi==0.1.4
Expand Down Expand Up @@ -2428,7 +2428,7 @@ streamlabswater==1.0.1
stringcase==1.2.0

# homeassistant.components.subaru
subarulink==0.7.5
subarulink==0.7.6

# homeassistant.components.solarlog
sunwatcher==0.2.1
Expand Down Expand Up @@ -2692,13 +2692,13 @@ zamg==0.2.2
zengge==0.2

# homeassistant.components.zeroconf
zeroconf==0.55.0
zeroconf==0.56.0

# homeassistant.components.zeversolar
zeversolar==0.3.1

# homeassistant.components.zha
zha-quirks==0.0.95
zha-quirks==0.0.96

# homeassistant.components.zhong_hong
zhong_hong_hvac==1.0.9
Expand Down
Loading

0 comments on commit a739f18

Please sign in to comment.