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

Refactor cover platform #13

Merged
merged 16 commits into from
Jun 5, 2020
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0]
### Added

- Added support for Gate devices

### Changed

- Removed all hardcoded device strings from the cover component

## [1.0.0] - 04-06-2020

### Added

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ This component is an updated version of the [original Tahoma integration](https:

### Manual

Copy the `custom_components/tahoma` to your `custom_components` folder. Reboot home assistant and install the Tahoma integration via the integrations config flow.
Copy the `custom_components/tahoma` to your `custom_components` folder. Reboot Home Assistant and install the Tahoma integration via the integrations page.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say "configure the Tahoma integration" instead of "install"

Copy link
Owner Author

Choose a reason for hiding this comment

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

Can you give it some love in another PR? I guess there are more parts that benefit from more clear text, especially around how to install beta's and the risk.


### HACS

Add the repository url below to HACS, search for the `Tahoma` integration and choose install. Reboot home assistant and install the Tahoma integration via the integrations config flow.
Add the repository url below to HACS, search for the `Tahoma` integration and choose install. Reboot Home Assistant and install the Tahoma integration via the integrations page.

```
https://github.com/imicknl/ha-tahoma
Expand All @@ -25,25 +25,27 @@ https://github.com/imicknl/ha-tahoma
This component doesn't have a hardcoded list of devices anymore, but relies on the `uiclass` of every Somfy device. This way more devices will be supported out of the box, based on their category and available states and commands.

If your device is not supported, it will show the following message in the logging. You can use this to create a new issue in the repository to see if the component can be added.

`Unsupported Tahoma device (internal:TSKAlarmComponent - Alarm - TSKAlarmController)`

| Somfy uiClass | Home Assistant platform |
| ----------------- | ----------------------- |
| Awning | cover |
| ExteriorScreen | cover |
| Gate | cover |
| GarageDoor | cover |
| Pergola | cover |
| RollerShutter | cover |
| Window | cover |
| TemperatureSensor | sensor |
| HumiditySensor | sensor |
| LightSensor | sensor |
| TemperatureSensor | sensor |
| DoorLock | lock |
| OnOff | switch |
| LightSensor | sensor |
| GarageDoor | cover |
| ContactSensor | binary_sensor |
| SmokeSensor | binary_sensor |
| OccupancySensor | binary_sensor |
| SmokeSensor | binary_sensor |
| Light | light |
| Awning | cover |

## Not supported (yet)

Expand Down
19 changes: 13 additions & 6 deletions custom_components/tahoma/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
_LOGGER = logging.getLogger(__name__)

# TODO adjust the data schema to the data that you need
DATA_SCHEMA = vol.Schema({CONF_USERNAME: str, CONF_PASSWORD: str})
DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str
})


async def validate_input(hass: core.HomeAssistant, data):
"""Validate the user input allows us to connect.

Data has the keys from DATA_SCHEMA with values provided by the user.
"""
# TODO use async executor?

username = data.get(CONF_USERNAME)
password = data.get(CONF_PASSWORD)

try:
api = TahomaApi(username, password)
controller = await hass.async_add_executor_job(TahomaApi, username, password)

except RequestException:
_LOGGER.exception("Error when trying to log in to the Tahoma API")
raise CannotConnect
Expand All @@ -49,11 +52,16 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_user(self, user_input=None):
"""Handle the initial step."""
errors = {}

if user_input is not None:
unique_id = user_input.get(CONF_USERNAME)
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured()

try:
info = await validate_input(self.hass, user_input)

return self.async_create_entry(title=info["title"], data=user_input)

except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAuth:
Expand All @@ -66,7 +74,6 @@ async def async_step_user(self, user_input=None):
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)


class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""

Expand Down
14 changes: 10 additions & 4 deletions custom_components/tahoma/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
DEVICE_CLASS_GARAGE,
DEVICE_CLASS_SHUTTER,
DEVICE_CLASS_WINDOW,
DEVICE_CLASS_GATE
)

from homeassistant.components.binary_sensor import (
Expand All @@ -17,7 +18,7 @@

DOMAIN = "tahoma"

# Tahoma to Home Assistant mapping
# Used to map the Somfy uiClass to the Home Assistant platform
TAHOMA_TYPES = {
"Light": "light",
"ExteriorScreen": "cover",
Expand All @@ -36,9 +37,11 @@
"SmokeSensor": "binary_sensor",
"OccupancySensor": "binary_sensor",
"ExteriorVenetianBlind": "cover",
"Awning": "cover"
"Awning": "cover",
"Gate": "cover"
}

# Used to map the Somfy widget or uiClass to the Home Assistant device classes
TAHOMA_COVER_DEVICE_CLASSES = {
"Awning": DEVICE_CLASS_AWNING,
"ExteriorScreen": DEVICE_CLASS_BLIND,
Expand All @@ -48,9 +51,11 @@
"Blind": DEVICE_CLASS_BLIND,
"GarageDoor": DEVICE_CLASS_GARAGE,
"ExteriorVenetianBlind": DEVICE_CLASS_BLIND,
"VeluxInteriorBlind": DEVICE_CLASS_BLIND
"VeluxInteriorBlind": DEVICE_CLASS_BLIND,
"Gate": DEVICE_CLASS_GATE
}

# Used to map the Somfy widget or uiClass to the Home Assistant device classes
TAHOMA_BINARY_SENSOR_DEVICE_CLASSES = {
"SmokeSensor": DEVICE_CLASS_SMOKE,
"OccupancySensor": DEVICE_CLASS_OCCUPANCY,
Expand Down Expand Up @@ -79,11 +84,12 @@
CORE_TEMPERATURE_STATE = "core:TemperatureState"
CORE_LUMINANCE_STATE = "core:LuminanceState"
CORE_RELATIVE_HUMIDITY_STATE = "core:RelativeHumidityState"

CORE_MEMORIZED_1_POSITION_STATE = "core:Memorized1PositionState"

IO_PRIORITY_LOCK_LEVEL_STATE = "io:PriorityLockLevelState"
IO_PRIORITY_LOCK_ORIGINATOR_STATE = "io:PriorityLockOriginatorState"

# Commands
COMMAND_SET_CLOSURE = "setClosure"
COMMAND_SET_POSITION = "setPosition"
COMMAND_SET_ORIENTATION = "setOrientation"
Loading