Skip to content

Commit

Permalink
Merge pull request #65 from natekspencer/dev
Browse files Browse the repository at this point in the history
Release 2022.12.0
  • Loading branch information
natekspencer authored Dec 9, 2022
2 parents f458365 + ef7311c commit f53462b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
39 changes: 39 additions & 0 deletions custom_components/vivint/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Support for Vivint binary sensors."""
from __future__ import annotations

from datetime import datetime, timedelta

from vivintpy.devices import VivintDevice
Expand All @@ -15,6 +17,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_call_later
from homeassistant.util.dt import utcnow
Expand Down Expand Up @@ -51,6 +54,18 @@ async def async_setup_entry(
entity_description=ENTITY_DESCRIPTION_MOTION,
)
)
elif hasattr(device, "node_online"):
entities.append(
VivintOnlineBinarySensorEntity(
device=device, hub=hub, key="node_online"
)
)
elif hasattr(device, "is_online"):
entities.append(
VivintOnlineBinarySensorEntity(
device=device, hub=hub, key="is_online"
)
)

if not entities:
return
Expand Down Expand Up @@ -199,3 +214,27 @@ def async_cancel_motion_stopped_callback(self) -> None:
if self._motion_stopped_callback is not None:
self._motion_stopped_callback()
self._motion_stopped_callback = None


class VivintOnlineBinarySensorEntity(VivintEntity, BinarySensorEntity):
"""Vivint online binary sensor entity."""

_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_has_entity_name = True
_attr_name = "Online"

def __init__(self, device: VivintDevice, hub: VivintHub, key: str) -> None:
"""Initialize a Vivint online binary sensor entity."""
super().__init__(device=device, hub=hub)
self._key = key

@property
def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self.device.alarm_panel.id}-{self.device.id}-online"

@property
def is_on(self) -> bool:
"""Return true if the binary sensor is on."""
return getattr(self.device, self._key)
9 changes: 8 additions & 1 deletion custom_components/vivint/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,19 @@ async def async_step_mfa(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle a multi-factor authentication (MFA) flow."""
super().async_step_user()
await super().async_step_user()
if user_input is None:
return self.async_show_form(step_id="mfa", data_schema=STEP_MFA_DATA_SCHEMA)

try:
await self._hub.verify_mfa(user_input[CONF_MFA])
except VivintSkyApiAuthenticationError as err: # pylint: disable=broad-except
_LOGGER.error(err)
return self.async_show_form(
step_id="mfa",
data_schema=STEP_MFA_DATA_SCHEMA,
errors={"base": str(err)},
)
except Exception as ex: # pylint: disable=broad-except
_LOGGER.error(ex)
return self.async_show_form(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/vivint/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ def device_info(self) -> DeviceInfo:
sw_version=device.software_version,
via_device=None
if isinstance(device, AlarmPanel)
else (DOMAIN, device.alarm_panel.id),
else get_device_id(device.alarm_panel),
)
17 changes: 6 additions & 11 deletions custom_components/vivint/manifest.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{
"domain": "vivint",
"name": "Vivint",
"version": "2022.6.2",
"version": "2022.12.0",
"config_flow": true,
"documentation": "https://github.com/natekspencer/hacs-vivint",
"issue_tracker": "https://github.com/natekspencer/hacs-vivint/issues",
"requirements": [
"vivintpy==2022.6.0"
],
"dependencies": [
"ffmpeg"
],
"codeowners": [
"@natekspencer"
]
}
"requirements": ["vivintpy==2022.12.0"],
"dependencies": ["ffmpeg"],
"codeowners": ["@natekspencer"],
"zeroconf": ["_vivint-ODC300._tcp.local.", "_vivint-DBC350._tcp.local."]
}

0 comments on commit f53462b

Please sign in to comment.