Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
persist-credentials: false

- name: Initialize CodeQL
uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
uses: github/codeql-action/init@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4.38.0
with:
languages: python

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9
uses: github/codeql-action/analyze@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4.38.0
with:
category: "/language:python"
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
exclude_types: [csv, json, html]
exclude: ^tests/fixtures/|homeassistant/generated/|tests/components/.*/snapshots/
- repo: https://github.com/zizmorcore/zizmor-pre-commit
rev: v1.30.0
rev: v1.30.1
hooks:
- id: zizmor
args:
Expand Down
10 changes: 10 additions & 0 deletions homeassistant/components/airthings_ble/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,14 @@ async def _async_update_data(self) -> AirthingsDevice:
data = await self.airthings.update_device(self.ble_device)
except Exception as err:
raise UpdateFailed(f"Unable to fetch data: {err}") from err

if not data.address:
# The device did not report its address, which means the read did not
# complete. Building entities from this would create a duplicate device
# and entities with an empty unique id prefix.
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="incomplete_read",
)

return data
3 changes: 3 additions & 0 deletions homeassistant/components/airthings_ble/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
"exceptions": {
"device_not_found": {
"message": "Could not find Airthings device with address {address}: {reason}"
},
"incomplete_read": {
"message": "The Airthings device did not return complete data, retrying"
}
}
}
7 changes: 5 additions & 2 deletions homeassistant/components/alarm_control_panel/device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
from homeassistant.helpers.entity import get_supported_features
from homeassistant.helpers.typing import ConfigType, TemplateVarsType

from . import DOMAIN
from .const import AlarmControlPanelEntityFeature, AlarmControlPanelEntityStateAttribute
from .const import (
DOMAIN,
AlarmControlPanelEntityFeature,
AlarmControlPanelEntityStateAttribute,
)

ACTION_TYPES: Final[set[str]] = {
"arm_away",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from homeassistant.helpers.entity import get_supported_features
from homeassistant.helpers.typing import ConfigType, TemplateVarsType

from . import DOMAIN, AlarmControlPanelState
from . import AlarmControlPanelState
from .const import (
CONDITION_ARMED_AWAY,
CONDITION_ARMED_CUSTOM_BYPASS,
Expand All @@ -31,6 +31,7 @@
CONDITION_ARMED_VACATION,
CONDITION_DISARMED,
CONDITION_TRIGGERED,
DOMAIN,
AlarmControlPanelEntityFeature,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType

from . import DOMAIN, AlarmControlPanelState
from .const import AlarmControlPanelEntityFeature
from . import AlarmControlPanelState
from .const import DOMAIN, AlarmControlPanelEntityFeature

BASIC_TRIGGER_TYPES: Final[set[str]] = {"triggered", "disarmed", "arming"}
TRIGGER_TYPES: Final[set[str]] = BASIC_TRIGGER_TYPES | {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
)
from homeassistant.core import Context, HomeAssistant, State

from . import DOMAIN, AlarmControlPanelState
from . import AlarmControlPanelState
from .const import DOMAIN

_LOGGER: Final = logging.getLogger(__name__)

Expand Down
101 changes: 3 additions & 98 deletions homeassistant/components/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""Component to interface with binary sensors."""

from datetime import timedelta
from enum import StrEnum
import logging
from typing import Final, Literal, final, override
from typing import Literal, final, override

import probatio
from propcache.api import cached_property

from homeassistant.config_entries import ConfigEntry
Expand All @@ -18,110 +16,17 @@
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.hass_dict import HassKey

from .const import DEVICE_CLASSES_SCHEMA, DOMAIN, BinarySensorDeviceClass # noqa: F401

_LOGGER = logging.getLogger(__name__)

DOMAIN: Final = "binary_sensor"
DATA_COMPONENT: HassKey[EntityComponent[BinarySensorEntity]] = HassKey(DOMAIN)
ENTITY_ID_FORMAT = DOMAIN + ".{}"
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
SCAN_INTERVAL = timedelta(seconds=30)


class BinarySensorDeviceClass(StrEnum):
"""Device class for binary sensors."""

# On means low, Off means normal
BATTERY = "battery"

# On means charging, Off means not charging
BATTERY_CHARGING = "battery_charging"

# On means carbon monoxide detected, Off means no carbon monoxide (clear)
CO = "carbon_monoxide"

# On means cold, Off means normal
COLD = "cold"

# On means connected, Off means disconnected
CONNECTIVITY = "connectivity"

# On means open, Off means closed
DOOR = "door"

# On means open, Off means closed
GARAGE_DOOR = "garage_door"

# On means gas detected, Off means no gas (clear)
GAS = "gas"

# On means glass break detected, Off means no glass break (clear)
GLASS_BREAK = "glass_break"

# On means hot, Off means normal
HEAT = "heat"

# On means light detected, Off means no light
LIGHT = "light"

# On means open (unlocked), Off means closed (locked)
LOCK = "lock"

# On means wet, Off means dry
MOISTURE = "moisture"

# On means motion detected, Off means no motion (clear)
MOTION = "motion"

# On means moving, Off means not moving (stopped)
MOVING = "moving"

# On means occupied, Off means not occupied (clear)
OCCUPANCY = "occupancy"

# On means open, Off means closed
OPENING = "opening"

# On means plugged in, Off means unplugged
PLUG = "plug"

# On means power detected, Off means no power
POWER = "power"

# On means home, Off means away
PRESENCE = "presence"

# On means problem detected, Off means no problem (OK)
PROBLEM = "problem"

# On means running, Off means not running
RUNNING = "running"

# On means unsafe, Off means safe
SAFETY = "safety"

# On means smoke detected, Off means no smoke (clear)
SMOKE = "smoke"

# On means sound detected, Off means no sound (clear)
SOUND = "sound"

# On means tampering detected, Off means no tampering (clear)
TAMPER = "tamper"

# On means update available, Off means up-to-date
UPDATE = "update"

# On means vibration detected, Off means no vibration
VIBRATION = "vibration"

# On means open, Off means closed
WINDOW = "window"


DEVICE_CLASSES_SCHEMA = probatio.All(
probatio.Lower, probatio.Coerce(BinarySensorDeviceClass)
)
DEVICE_CLASSES = [cls.value for cls in BinarySensorDeviceClass]

# mypy: disallow-any-generics
Expand Down
104 changes: 104 additions & 0 deletions homeassistant/components/binary_sensor/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""Constants for the binary_sensor integration."""

from enum import StrEnum
from typing import Final

import probatio

DOMAIN: Final = "binary_sensor"


class BinarySensorDeviceClass(StrEnum):
"""Device class for binary sensors."""

# On means low, Off means normal
BATTERY = "battery"

# On means charging, Off means not charging
BATTERY_CHARGING = "battery_charging"

# On means carbon monoxide detected, Off means no carbon monoxide (clear)
CO = "carbon_monoxide"

# On means cold, Off means normal
COLD = "cold"

# On means connected, Off means disconnected
CONNECTIVITY = "connectivity"

# On means open, Off means closed
DOOR = "door"

# On means open, Off means closed
GARAGE_DOOR = "garage_door"

# On means gas detected, Off means no gas (clear)
GAS = "gas"

# On means glass break detected, Off means no glass break (clear)
GLASS_BREAK = "glass_break"

# On means hot, Off means normal
HEAT = "heat"

# On means light detected, Off means no light
LIGHT = "light"

# On means open (unlocked), Off means closed (locked)
LOCK = "lock"

# On means wet, Off means dry
MOISTURE = "moisture"

# On means motion detected, Off means no motion (clear)
MOTION = "motion"

# On means moving, Off means not moving (stopped)
MOVING = "moving"

# On means occupied, Off means not occupied (clear)
OCCUPANCY = "occupancy"

# On means open, Off means closed
OPENING = "opening"

# On means plugged in, Off means unplugged
PLUG = "plug"

# On means power detected, Off means no power
POWER = "power"

# On means home, Off means away
PRESENCE = "presence"

# On means problem detected, Off means no problem (OK)
PROBLEM = "problem"

# On means running, Off means not running
RUNNING = "running"

# On means unsafe, Off means safe
SAFETY = "safety"

# On means smoke detected, Off means no smoke (clear)
SMOKE = "smoke"

# On means sound detected, Off means no sound (clear)
SOUND = "sound"

# On means tampering detected, Off means no tampering (clear)
TAMPER = "tamper"

# On means update available, Off means up-to-date
UPDATE = "update"

# On means vibration detected, Off means no vibration
VIBRATION = "vibration"

# On means open, Off means closed
WINDOW = "window"


DEVICE_CLASSES_SCHEMA = probatio.All(
probatio.Lower, probatio.Coerce(BinarySensorDeviceClass)
)
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/device_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from homeassistant.helpers.entity import get_device_class
from homeassistant.helpers.typing import ConfigType

from . import DOMAIN, BinarySensorDeviceClass
from .const import DOMAIN, BinarySensorDeviceClass

# mypy: disallow-any-generics

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/binary_sensor/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType

from . import DOMAIN, BinarySensorDeviceClass
from .const import DOMAIN, BinarySensorDeviceClass

DEVICE_CLASS_NONE = "none"

Expand Down
19 changes: 6 additions & 13 deletions homeassistant/components/button/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""Component to pressing a button as platforms."""

from datetime import timedelta
from enum import StrEnum
import logging
from typing import final, override

import probatio
from propcache.api import cached_property

from homeassistant.config_entries import ConfigEntry
Expand All @@ -19,7 +17,12 @@
from homeassistant.util import dt as dt_util
from homeassistant.util.hass_dict import HassKey

from .const import DOMAIN, SERVICE_PRESS
from .const import ( # noqa: F401
DEVICE_CLASSES_SCHEMA,
DOMAIN,
SERVICE_PRESS,
ButtonDeviceClass,
)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -32,16 +35,6 @@
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)


class ButtonDeviceClass(StrEnum):
"""Device class for buttons."""

IDENTIFY = "identify"
RESTART = "restart"
UPDATE = "update"


DEVICE_CLASSES_SCHEMA = probatio.All(probatio.Lower, probatio.Coerce(ButtonDeviceClass))

# mypy: disallow-any-generics


Expand Down
Loading
Loading