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

Fix line-endings. #84

Open
wants to merge 2 commits into
base: main
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
246 changes: 123 additions & 123 deletions custom_components/cync_lights/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,123 +1,123 @@
"""Platform for binary sensor integration."""
from __future__ import annotations
from typing import Any
from homeassistant.components.binary_sensor import (BinarySensorDeviceClass, BinarySensorEntity)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.entity import DeviceInfo
from .const import DOMAIN
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback
) -> None:
hub = hass.data[DOMAIN][config_entry.entry_id]
new_devices = []
for sensor in hub.cync_motion_sensors:
if not hub.cync_motion_sensors[sensor]._update_callback and sensor in config_entry.options["motion_sensors"]:
new_devices.append(CyncMotionSensorEntity(hub.cync_motion_sensors[sensor]))
for sensor in hub.cync_ambient_light_sensors:
if not hub.cync_ambient_light_sensors[sensor]._update_callback and sensor in config_entry.options["ambient_light_sensors"]:
new_devices.append(CyncAmbientLightSensorEntity(hub.cync_ambient_light_sensors[sensor]))
if new_devices:
async_add_entities(new_devices)
class CyncMotionSensorEntity(BinarySensorEntity):
"""Representation of a Cync Motion Sensor."""
should_poll = False
def __init__(self, motion_sensor) -> None:
"""Initialize the sensor."""
self.motion_sensor = motion_sensor
async def async_added_to_hass(self) -> None:
"""Run when this Entity has been added to HA."""
self.motion_sensor.register(self.async_write_ha_state)
async def async_will_remove_from_hass(self) -> None:
"""Entity being removed from hass."""
self.motion_sensor.reset()
@property
def device_info(self) -> DeviceInfo:
"""Return device registry information for this entity."""
return DeviceInfo(
identifiers = {(DOMAIN, f"{self.motion_sensor.room.name} ({self.motion_sensor.home_name})")},
manufacturer = "Cync by Savant",
name = f"{self.motion_sensor.room.name} ({self.motion_sensor.home_name})",
suggested_area = f"{self.motion_sensor.room.name}",
)
@property
def unique_id(self) -> str:
"""Return Unique ID string."""
return 'cync_motion_sensor_' + self.motion_sensor.device_id
@property
def name(self) -> str:
"""Return the name of the motion_sensor."""
return self.motion_sensor.name + " Motion"
@property
def is_on(self) -> bool | None:
"""Return true if light is on."""
return self.motion_sensor.motion
@property
def device_class(self) -> str | None:
"""Return the device class"""
return BinarySensorDeviceClass.MOTION
class CyncAmbientLightSensorEntity(BinarySensorEntity):
"""Representation of a Cync Ambient Light Sensor."""
should_poll = False
def __init__(self, ambient_light_sensor) -> None:
"""Initialize the sensor."""
self.ambient_light_sensor = ambient_light_sensor
async def async_added_to_hass(self) -> None:
"""Run when this Entity has been added to HA."""
self.ambient_light_sensor.register(self.async_write_ha_state)
async def async_will_remove_from_hass(self) -> None:
"""Entity being removed from hass."""
self.ambient_light_sensor.reset()
@property
def device_info(self) -> DeviceInfo:
"""Return device registry information for this entity."""
return DeviceInfo(
identifiers = {(DOMAIN, f"{self.ambient_light_sensor.room.name} ({self.ambient_light_sensor.home_name})")},
manufacturer = "Cync by Savant",
name = f"{self.ambient_light_sensor.room.name} ({self.ambient_light_sensor.home_name})",
suggested_area = f"{self.ambient_light_sensor.room.name}",
)
@property
def unique_id(self) -> str:
"""Return Unique ID string."""
return 'cync_ambient_light_sensor_' + self.ambient_light_sensor.device_id
@property
def name(self) -> str:
"""Return the name of the ambient_light_sensor."""
return self.ambient_light_sensor.name + " Ambient Light"
@property
def is_on(self) -> bool | None:
"""Return true if light is on."""
return self.ambient_light_sensor.ambient_light
@property
def device_class(self) -> str | None:
"""Return the device class"""
return BinarySensorDeviceClass.LIGHT
"""Platform for binary sensor integration."""
from __future__ import annotations
from typing import Any
from homeassistant.components.binary_sensor import (BinarySensorDeviceClass, BinarySensorEntity)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.entity import DeviceInfo
from .const import DOMAIN

async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback
) -> None:
hub = hass.data[DOMAIN][config_entry.entry_id]

new_devices = []
for sensor in hub.cync_motion_sensors:
if not hub.cync_motion_sensors[sensor]._update_callback and sensor in config_entry.options["motion_sensors"]:
new_devices.append(CyncMotionSensorEntity(hub.cync_motion_sensors[sensor]))
for sensor in hub.cync_ambient_light_sensors:
if not hub.cync_ambient_light_sensors[sensor]._update_callback and sensor in config_entry.options["ambient_light_sensors"]:
new_devices.append(CyncAmbientLightSensorEntity(hub.cync_ambient_light_sensors[sensor]))

if new_devices:
async_add_entities(new_devices)


class CyncMotionSensorEntity(BinarySensorEntity):
"""Representation of a Cync Motion Sensor."""

should_poll = False

def __init__(self, motion_sensor) -> None:
"""Initialize the sensor."""
self.motion_sensor = motion_sensor

async def async_added_to_hass(self) -> None:
"""Run when this Entity has been added to HA."""
self.motion_sensor.register(self.async_write_ha_state)

async def async_will_remove_from_hass(self) -> None:
"""Entity being removed from hass."""
self.motion_sensor.reset()

@property
def device_info(self) -> DeviceInfo:
"""Return device registry information for this entity."""
return DeviceInfo(
identifiers = {(DOMAIN, f"{self.motion_sensor.room.name} ({self.motion_sensor.home_name})")},
manufacturer = "Cync by Savant",
name = f"{self.motion_sensor.room.name} ({self.motion_sensor.home_name})",
suggested_area = f"{self.motion_sensor.room.name}",
)

@property
def unique_id(self) -> str:
"""Return Unique ID string."""
return 'cync_motion_sensor_' + self.motion_sensor.device_id

@property
def name(self) -> str:
"""Return the name of the motion_sensor."""
return self.motion_sensor.name + " Motion"

@property
def is_on(self) -> bool | None:
"""Return true if light is on."""
return self.motion_sensor.motion

@property
def device_class(self) -> str | None:
"""Return the device class"""
return BinarySensorDeviceClass.MOTION

class CyncAmbientLightSensorEntity(BinarySensorEntity):
"""Representation of a Cync Ambient Light Sensor."""

should_poll = False

def __init__(self, ambient_light_sensor) -> None:
"""Initialize the sensor."""
self.ambient_light_sensor = ambient_light_sensor

async def async_added_to_hass(self) -> None:
"""Run when this Entity has been added to HA."""
self.ambient_light_sensor.register(self.async_write_ha_state)

async def async_will_remove_from_hass(self) -> None:
"""Entity being removed from hass."""
self.ambient_light_sensor.reset()

@property
def device_info(self) -> DeviceInfo:
"""Return device registry information for this entity."""
return DeviceInfo(
identifiers = {(DOMAIN, f"{self.ambient_light_sensor.room.name} ({self.ambient_light_sensor.home_name})")},
manufacturer = "Cync by Savant",
name = f"{self.ambient_light_sensor.room.name} ({self.ambient_light_sensor.home_name})",
suggested_area = f"{self.ambient_light_sensor.room.name}",
)

@property
def unique_id(self) -> str:
"""Return Unique ID string."""
return 'cync_ambient_light_sensor_' + self.ambient_light_sensor.device_id

@property
def name(self) -> str:
"""Return the name of the ambient_light_sensor."""
return self.ambient_light_sensor.name + " Ambient Light"

@property
def is_on(self) -> bool | None:
"""Return true if light is on."""
return self.ambient_light_sensor.ambient_light

@property
def device_class(self) -> str | None:
"""Return the device class"""
return BinarySensorDeviceClass.LIGHT

8 changes: 4 additions & 4 deletions custom_components/cync_lights/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
STEP_USER_DATA_SCHEMA = vol.Schema(
{
vol.Required("username"): str,
vol.Required("password"): str,
vol.Required("password"): str,
}
)
STEP_TWO_FACTOR_CODE = vol.Schema(
Expand Down Expand Up @@ -145,7 +145,7 @@ async def async_step_select_switches(
): cv.multi_select({device_id : f'{device_info["name"]} ({device_info["room_name"]}:{device_info["home_name"]})' for device_id,device_info in self.data["data"]["cync_config"]["devices"].items() if device_info.get('AMBIENT_LIGHT',False)}),
}
)

return self.async_show_form(step_id="select_switches", data_schema=switches_data_schema)

async def _async_finish_setup(
Expand All @@ -154,7 +154,7 @@ async def _async_finish_setup(
"""Finish setup and create entry"""

existing_entry = await self.async_set_unique_id(self.data['title'])
if not existing_entry:
if not existing_entry:
return self.async_create_entry(title=self.data["title"], data=self.data["data"], options=self.options)
else:
self.hass.config_entries.async_update_entry(existing_entry, data=self.data['data'], options=self.options)
Expand Down Expand Up @@ -286,4 +286,4 @@ class TwoFactorCodeRequired(HomeAssistantError):
"""Error to indicate we cannot connect."""

class InvalidAuth(HomeAssistantError):
"""Error to indicate there is invalid auth."""
"""Error to indicate there is invalid auth."""
Loading