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

Adding Climate and Fan Support #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions custom_components/control4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
Platform.LIGHT,
Platform.ALARM_CONTROL_PANEL,
Platform.BINARY_SENSOR,
Platform.FAN,
Platform.CLIMATE,
Platform.LOCK,
]

Expand All @@ -72,7 +74,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

# Add Control4 controller to device registry
try:
controller_href = (await entry_data[CONF_ACCOUNT].getAccountControllers())["href"]
controller_href = (await entry_data[CONF_ACCOUNT].getAccountControllers())[
"href"
]
except (client_exceptions.ClientError, asyncio.TimeoutError) as exception:
raise ConfigEntryNotReady(exception) from exception

Expand Down Expand Up @@ -168,10 +172,13 @@ async def get_items_of_category(hass: HomeAssistant, entry: ConfigEntry, categor
return_list = await director.getAllItemsByCategory(category)
return json.loads(return_list)
except InvalidCategory as e:
_LOGGER.warning("Category %s does not exist on this Control4 system, \
entities from this domain will not be setup.", category, exc_info=True)
_LOGGER.warning(
"Category %s does not exist on this Control4 system, \
entities from this domain will not be setup.",
category,
exc_info=True,
)
return []



async def refresh_tokens(hass: HomeAssistant, entry: ConfigEntry):
Expand Down
19 changes: 16 additions & 3 deletions custom_components/control4/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ def __init__(
)
self._device_class = device_class
self._extra_state_attributes["alarm_zone_id"] = alarm_zone_id
self._extra_state_attributes["ContactState"] = bool(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these changes do? They seem unrelated to fan/climate support. Could you separate these changes out into a different PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have many more changes to the binary_sensor, I have found several different messages sent by different c4 binary sensors around the house. I am not good with git, but I will try!

self._extra_state_attributes["ContactState"]
if "ContactState" in self._extra_state_attributes:
self._extra_state_attributes["ContactState"] = bool(
self._extra_state_attributes["ContactState"]
)
self._extra_state_attributes["StateVerified"] = bool(
self._extra_state_attributes["StateVerified"]
Expand All @@ -231,6 +232,12 @@ async def _update_callback(self, device, message):
self._attr_available = True
data = message["data"]
# Extra handling for alarm specific messages
if "zone_state" in data:
self._extra_state_attributes["ContactState"] = bool(
not data["zone_state"].pop("is_open")
)
self._extra_state_attributes["LastActionTime"] = message["time"]

if "contact_state" in data:
self._extra_state_attributes["ContactState"] = bool(
data["contact_state"].pop("current_state") == "CLOSED"
Expand All @@ -249,7 +256,13 @@ def is_on(self):
# In Control4, True = closed/clear and False = open/not clear
# For some reason, Control4 gives us ContactState on entity init,
# but updates STATE when changes occur (the value of ContactState is never updated)
return not bool(self.extra_state_attributes["ContactState"])
if "ContactState" not in self._extra_state_attributes:
return False
_LOGGER.warning(
"ContactState not found in extra_state_attributes: %s",
str(self._extra_state_attributes),
)
return not bool(self._extra_state_attributes["ContactState"])

@property
def device_class(self):
Expand Down
Loading