Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump total_connect_client to 2024 4 #116358

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
867a0a6
add button for totalconnect
austinmroczek Mar 31, 2024
3b933c8
test button for totalconnect
austinmroczek Mar 31, 2024
e4c4fcf
change to zone.can_be_bypassed
austinmroczek Mar 31, 2024
53074cf
Update homeassistant/components/totalconnect/button.py
austinmroczek Apr 2, 2024
8fb30d7
Update homeassistant/components/totalconnect/button.py
austinmroczek Apr 2, 2024
43be1f1
Update homeassistant/components/totalconnect/button.py
austinmroczek Apr 2, 2024
01b8044
remove unused logging
austinmroczek Apr 2, 2024
ffa75a8
Update homeassistant/components/totalconnect/button.py
austinmroczek Apr 21, 2024
6d42879
Update homeassistant/components/totalconnect/button.py
austinmroczek Apr 21, 2024
78d76a0
fix button and test
austinmroczek Apr 21, 2024
cedbfab
Revert "bump total_connect_client to 2023.12.1"
austinmroczek Apr 21, 2024
b077ab9
bump total_connect_client to 2023.12.1
austinmroczek Mar 31, 2024
6239d6d
use ZoneEntity for Bypass button
austinmroczek Apr 26, 2024
bf2d468
use LocationEntity for PanelButton
austinmroczek Apr 26, 2024
7bbbb61
fix typing
austinmroczek Apr 26, 2024
d11fa2f
add translation_key for panel buttons
austinmroczek Apr 26, 2024
9dc5913
mock clear_bypass instead of disarm
austinmroczek Apr 26, 2024
5c2a10e
use paramaterize
austinmroczek Apr 27, 2024
35c76f4
use snapshot
austinmroczek Apr 27, 2024
f4f7fd5
sentence case in strings
austinmroczek Apr 27, 2024
9561380
remove un-needed stuff
austinmroczek Apr 28, 2024
5dcb670
bump total_connect_client to 2024.4
austinmroczek Apr 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/totalconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from .const import AUTO_BYPASS, CONF_USERCODES, DOMAIN

PLATFORMS = [Platform.ALARM_CONTROL_PANEL, Platform.BINARY_SENSOR]
PLATFORMS = [Platform.ALARM_CONTROL_PANEL, Platform.BINARY_SENSOR, Platform.BUTTON]

CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
SCAN_INTERVAL = timedelta(seconds=30)
Expand Down
104 changes: 104 additions & 0 deletions homeassistant/components/totalconnect/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""Interfaces with TotalConnect buttons."""

from collections.abc import Callable
from dataclasses import dataclass

from total_connect_client.location import TotalConnectLocation
from total_connect_client.zone import TotalConnectZone

from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import TotalConnectDataUpdateCoordinator
from .const import DOMAIN
from .entity import TotalConnectLocationEntity, TotalConnectZoneEntity


@dataclass(frozen=True, kw_only=True)
class TotalConnectButtonEntityDescription(ButtonEntityDescription):
"""TotalConnect button description."""

press_fn: Callable[[TotalConnectLocation], None]


PANEL_BUTTONS: tuple[TotalConnectButtonEntityDescription, ...] = (
TotalConnectButtonEntityDescription(
key="clear_bypass",
name="Clear Bypass",
translation_key="clear_bypass",
press_fn=lambda location: location.clear_bypass(),
),
TotalConnectButtonEntityDescription(
key="bypass_all",
name="Bypass All",
translation_key="bypass_all",
press_fn=lambda location: location.zone_bypass_all(),
),
)


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up TotalConnect buttons based on a config entry."""
buttons: list = []
coordinator: TotalConnectDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]

for location_id, location in coordinator.client.locations.items():
buttons.extend(
TotalConnectPanelButton(coordinator, location, description)
for description in PANEL_BUTTONS
)

buttons.extend(
TotalConnectZoneBypassButton(coordinator, zone, location_id)
for zone in location.zones.values()
if zone.can_be_bypassed
)

async_add_entities(buttons)


class TotalConnectZoneBypassButton(TotalConnectZoneEntity, ButtonEntity):
"""Represent a TotalConnect zone bypass button."""

_attr_translation_key = "bypass"
_attr_entity_category = EntityCategory.DIAGNOSTIC

def __init__(
self,
coordinator: TotalConnectDataUpdateCoordinator,
zone: TotalConnectZone,
location_id,
) -> None:
"""Initialize the TotalConnect status."""
super().__init__(coordinator, zone, location_id, "bypass")
self.entity_description = ButtonEntityDescription(key="bypass", name="bypass")

def press(self):
"""Press the bypass button."""
self._zone.bypass()


class TotalConnectPanelButton(TotalConnectLocationEntity, ButtonEntity):
"""Generic TotalConnect panel button."""

entity_description: TotalConnectButtonEntityDescription

def __init__(
self,
coordinator: TotalConnectDataUpdateCoordinator,
location: TotalConnectLocation,
entity_description: TotalConnectButtonEntityDescription,
) -> None:
"""Initialize the TotalConnect button."""
super().__init__(coordinator, location)
self.entity_description = entity_description
self._attr_unique_id = f"{location.location_id}_{entity_description.key}"

def press(self) -> None:
"""Press the button."""
self.entity_description.press_fn(self._location)
2 changes: 1 addition & 1 deletion homeassistant/components/totalconnect/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/totalconnect",
"iot_class": "cloud_polling",
"loggers": ["total_connect_client"],
"requirements": ["total-connect-client==2023.12.1"]
"requirements": ["total-connect-client==2024.4"]
}
8 changes: 8 additions & 0 deletions homeassistant/components/totalconnect/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
"partition": {
"name": "Partition {partition_id}"
}
},
"button": {
"clear_bypass": {
"name": "Clear bypass"
},
"bypass_all": {
"name": "Bypass all"
}
}
}
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ tololib==1.1.0
toonapi==0.3.0

# homeassistant.components.totalconnect
total-connect-client==2023.12.1
total-connect-client==2024.4

# homeassistant.components.tplink_lte
tp-connected==0.0.4
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,7 @@ tololib==1.1.0
toonapi==0.3.0

# homeassistant.components.totalconnect
total-connect-client==2023.12.1
total-connect-client==2024.4

# homeassistant.components.tplink_omada
tplink-omada-client==1.3.12
Expand Down
19 changes: 19 additions & 0 deletions tests/components/totalconnect/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@
"CanBeBypassed": 0,
}

# ZoneType security that cannot be bypassed is a Button on the alarm panel
ZONE_8 = {
"ZoneID": 8,
"ZoneDescription": "Button",
"ZoneStatus": ZoneStatus.FAULT,
"ZoneTypeId": ZoneType.SECURITY,
"PartitionId": "1",
"CanBeBypassed": 0,
}


ZONE_INFO = [ZONE_NORMAL, ZONE_2, ZONE_3, ZONE_4, ZONE_5, ZONE_6, ZONE_7]
ZONES = {"ZoneInfo": ZONE_INFO}

Expand Down Expand Up @@ -318,6 +329,14 @@
"ResultData": "testing user code invalid",
}
RESPONSE_SUCCESS = {"ResultCode": ResultCode.SUCCESS.value}
RESPONSE_ZONE_BYPASS_SUCCESS = {
"ResultCode": ResultCode.SUCCESS.value,
"ResultData": "None",
}
RESPONSE_ZONE_BYPASS_FAILURE = {
"ResultCode": ResultCode.FAILED_TO_BYPASS_ZONE.value,
"ResultData": "None",
}

USERNAME = "username@me.com"
PASSWORD = "password"
Expand Down