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

Smartir class #192

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion codes/light/1070.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"brightness": [
16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 255
],
"colorTemperature": [],
"commands": {
"on": "BZgjrRE/AuAXAQGDBuAFA0AB4AcTQA/gFwFAI+ALAwcQoZgj0Qg/Ag==",
"off": "B34jkRFpAhQC4BUDAWcG4AUDQC/gAxMAFCABQA8BFAJAA0ABQAfgAQMFZwYUAhQCQAfgDQMHOKF+I6MIaQI=",
Expand Down
151 changes: 151 additions & 0 deletions custom_components/smartir/device_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,155 @@ def check_file_media_player(file_name, device_data, device_class, check_data):

@staticmethod
def check_file_light(file_name, device_data, device_class, check_data):
color_modes = {}

if not (
"commands" in device_data
and isinstance(device_data["commands"], dict)
and len(device_data["commands"])
):
_LOGGER.error(
"Invalid %s device JSON file '%s': missing or invalid attribute 'commands'.",
device_class,
file_name,
)
return False
commands = device_data["commands"]

if "brightness" in device_data:
if not (
isinstance(device_data["brightness"], list)
and len(device_data["brightness"])
and sorted(device_data["brightness"]) == device_data["brightness"]
):
_LOGGER.error(
"Invalid %s device JSON file '%s': invalid parameter 'brightness'",
device_class,
file_name,
)
return False
color_modes["brightness"] = True
else:
for cmd in ["brightness", "dim", "brighten"]:
if cmd in commands:
_LOGGER.error(
"Invalid %s device JSON file '%s': invalid command '%s'",
device_class,
file_name,
cmd,
)
return False

if "colorTemperature" in device_data:
if not (
isinstance(device_data["colorTemperature"], list)
and len(device_data["colorTemperature"])
and sorted(device_data["colorTemperature"])
== device_data["colorTemperature"]
):
_LOGGER.error(
"Invalid %s device JSON file '%s': invalid parameter 'colorTemperature'",
device_class,
file_name,
)
return False
color_modes["color_temp"] = True
else:
for cmd in ["colorTemperature", "colder", "warmer"]:
if cmd in commands:
_LOGGER.error(
"Invalid %s device JSON file '%s': invalid command '%s'",
device_class,
file_name,
cmd,
)
return False

if "brightness" in color_modes:
if "brightness" in commands:
if not (
isinstance(commands["brightness"], list)
and len(commands["brightness"])
):
_LOGGER.error(
"Invalid %s device JSON file '%s': invalid commands 'brightness'",
device_class,
file_name,
)
return False

# check if same IR command were find in the device data
if not (
len(device_data["brightness"]) == len(commands["brightness"])
and all(
key in commands["brightness"]
for key in device_data["brightness"]
)
):
_LOGGER.info(
"Invalid %s device JSON file '%s': parameter 'brightness' and commands 'brightness' contain different keys.",
device_class,
file_name,
)
return False
elif not (
"dim" in commands
and isinstance(commands["dim"], str)
and "brighten" in commands
and isinstance(commands["brighten"], str)
):
_LOGGER.info(
"Invalid %s device JSON file '%s': parameter 'brightness' require either command 'brightness' or 'dim' and 'brighten' commands to be defined.",
device_class,
file_name,
)
return False

elif len(color_modes) > 1:
_LOGGER.error(
"Invalid %s device JSON file '%s': Any color mode require parameter 'brightness' to be defined as well",
device_class,
file_name,
)
return False

if "color_temp" in color_modes:
if "colorTemperature" in commands:
if not (
isinstance(commands["colorTemperature"], list)
and len(commands["colorTemperature"])
):
_LOGGER.error(
"Invalid %s device JSON file '%s': invalid commands 'colorTemperature'",
device_class,
file_name,
)
return False

# check if same IR command were find in the device data
if len(device_data["colorTemperature"]) == len(
commands["colorTemperature"]
) and all(
key in commands["colorTemperature"]
for key in device_data["colorTemperature"]
):
_LOGGER.info(
"Invalid %s device JSON file '%s': parameter 'colorTemperature' and commands 'colorTemperature' contain different keys.",
device_class,
file_name,
)
return False
elif not (
"colder" in commands
and isinstance(commands["colder"], str)
and "warmer" in commands
and isinstance(commands["warmer"], str)
):
_LOGGER.info(
"Invalid %s device JSON file '%s': parameter 'colorTemperature' require either command 'colorTemperature' or 'warmer' and 'colder' to be defined.",
device_class,
file_name,
)
return False

return True
4 changes: 2 additions & 2 deletions custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
DIRECTION_REVERSE,
DIRECTION_FORWARD,
)
from homeassistant.const import CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, Event, EventStateChangedData
from homeassistant.const import CONF_NAME, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType
Expand Down
Loading
Loading