-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3b96231
Showing
14 changed files
with
987 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Nenad Bogojevic | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
This is a custom component for Home assistant that adds support for Midea dehumidifier appliances via the local area network. | ||
|
||
# midea-dehumidifier-lan | ||
Home Assistant custom component for controlling Midea dehumidiferes on local network | ||
|
||
## Installation instruction | ||
|
||
### HACS | ||
Add this repository as custom integration repository to HACS. | ||
|
||
### Manual | ||
1. Update Home Assistant to version 2021.12 or newer | ||
2. Clone this repository | ||
3. Copy the `custom_components/midea_dehumidifier_local` folder into your Home Assistant's `custom_components` folder | ||
|
||
### Configuring | ||
1. Add `Midea Dehumidifer (LAN)` integration via UI | ||
2. Enter Midea cloud username and password. Those are the same used in Midea mobile application. | ||
3. The integration will discover dehumidifiers on local LAN network(s). | ||
4. If a dehumidifer is not automatically discovered, but is registered to the cloud account, user is prompted to enter IPv4 address of the dehumidifier. | ||
|
||
## Known issues | ||
|
||
* If IPv4 address of dehumidifer changes, new IPv4 address will not be used until Home Assistant's restart | ||
|
||
|
||
## Supported entities | ||
|
||
This custom component creates following entites for each discovered dehumidifer: | ||
|
||
* humidifier/dehumidifer | ||
* fan | ||
* sensor with current humidity | ||
* binary sensor for full tank | ||
* switch for controlling ION mode (switch has no effect if dehumidifier doesn't support it) | ||
|
||
## See also | ||
|
||
https://github.com/nbogojevic/midea-beautiful-dehumidifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
The custom component for local network access to Midea Dehumidifier | ||
""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import CONF_DEVICES, CONF_IP_ADDRESS, CONF_USERNAME, CONF_PASSWORD, CONF_TOKEN | ||
from .const import ( | ||
DOMAIN, | ||
PLATFORMS, | ||
CONF_APP_KEY, | ||
CONF_TOKEN_KEY | ||
) | ||
|
||
from midea_beautiful_dehumidifier import appliance_state, connect_to_cloud | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, entry: ConfigEntry | ||
) -> bool: | ||
"""Set up platform from a ConfigEntry.""" | ||
hass.data.setdefault(DOMAIN, {}) | ||
_LOGGER.debug("Configuration entry: %s", entry.data) | ||
|
||
hub = await hass.async_add_executor_job(Hub, hass, entry.data) | ||
hass.data[DOMAIN][entry.entry_id] = hub | ||
|
||
hass.config_entries.async_setup_platforms(entry, PLATFORMS) | ||
return True | ||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Unload a config entry.""" | ||
# This is called when an entry/configured device is to be removed. The class | ||
# needs to unload itself, and remove callbacks. See the classes for further | ||
# details | ||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
if unload_ok: | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
|
||
return unload_ok | ||
|
||
class Hub: | ||
def __init__(self, hass: HomeAssistant, data): | ||
self.cloud = connect_to_cloud( | ||
appkey=data[CONF_APP_KEY], | ||
account=data[CONF_USERNAME], | ||
password=data[CONF_PASSWORD], | ||
) | ||
self.appliances = [] | ||
for aconf in data[CONF_DEVICES]: | ||
app = appliance_state(aconf[CONF_IP_ADDRESS], token=aconf[CONF_TOKEN], key=aconf[CONF_TOKEN_KEY], cloud=self.cloud) | ||
self.appliances.append(app) | ||
|
||
|
51 changes: 51 additions & 0 deletions
51
custom_components/midea_dehumidifier_local/binary_sensor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from midea_beautiful_dehumidifier.lan import LanDevice | ||
from config.custom_components.midea_dehumidifier_local.const import DOMAIN | ||
from homeassistant.components.binary_sensor import BinarySensorEntity | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
hub = hass.data[DOMAIN][config_entry.entry_id] | ||
|
||
# Add all entities to HA | ||
async_add_entities( | ||
TankFullSensor(appliance) for appliance in hub.appliances | ||
) | ||
|
||
|
||
class TankFullSensor(BinarySensorEntity): | ||
def __init__(self, appliance: LanDevice) -> None: | ||
super().__init__() | ||
self._appliance = appliance | ||
self._unique_id = f"midea_dehumidifier_tank_full_{appliance.id}" | ||
|
||
@property | ||
def unique_id(self): | ||
"""Return the unique id.""" | ||
return self._unique_id | ||
|
||
@property | ||
def name(self): | ||
"""Return the unique id.""" | ||
return str(getattr(self._appliance.state, "name", self.unique_id)) + " Tank Full" | ||
|
||
@property | ||
def is_on(self): | ||
return getattr(self._appliance.state, "tank_full", False) | ||
|
||
@property | ||
def device_info(self): | ||
return { | ||
"identifiers": { | ||
(DOMAIN, self._appliance.sn) | ||
}, | ||
"name": self.name, | ||
"manufacturer": "Midea", | ||
"model": str(self._appliance.type), | ||
} |
Oops, something went wrong.