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

feat: migrate domain to midea_lan #159

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "midea_ac_lan",
"name": "midea_lan",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
id: check_version
run: |
# Extract the version from manifest.json
manifest_version=$(grep -oP '(?<="version": ")[^"]*' custom_components/midea_ac_lan/manifest.json)
manifest_version=$(grep -oP '(?<="version": ")[^"]*' custom_components/midea_lan/manifest.json)
echo "Manifest.json version: $manifest_version"
# Extract the release tag
release_tag="${GITHUB_REF#refs/tags/}"
Expand All @@ -50,21 +50,21 @@ jobs:
uname -a
echo "show runner pwd file list"
ls
ls -alht "custom_components/midea_ac_lan/" || exit 1
ls -alht "custom_components/midea_lan/" || exit 1
echo "show manifest.json for debug"
cat "custom_components/midea_ac_lan/manifest.json" || exit 1
cat "custom_components/midea_lan/manifest.json" || exit 1
dst_dir="/github/workspace/artifacts"
sudo mkdir -p "$dst_dir" || exit 1
sudo chown -R "$(id -u):$(id -g)" "$dst_dir" || exit 1
sudo chmod -R 755 "$dst_dir" || exit 1
cd "custom_components/midea_ac_lan/" || exit 1
zip -r ../midea_ac_lan.zip ./* || exit 1
cp ../midea_ac_lan.zip "$dst_dir/" || exit 1
cd "custom_components/midea_lan/" || exit 1
zip -r ../midea_lan.zip ./* || exit 1
cp ../midea_lan.zip "$dst_dir/" || exit 1
ls -alht "$dst_dir" || exit 1
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: midea_ac_lan.zip
name: midea_lan.zip
path: /github/workspace/artifacts

upload_release:
Expand All @@ -77,7 +77,7 @@ jobs:
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: midea_ac_lan.zip
pattern: midea_lan.zip
merge-multiple: true

- name: Display Structure of Artifacts Files
Expand Down Expand Up @@ -105,6 +105,6 @@ jobs:
- name: Upload images to Release Asset
uses: softprops/action-gh-release@v2
with:
files: artifacts/midea_ac_lan.zip
files: artifacts/midea_lan.zip
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ jobs:
- uses: "actions/checkout@v4"

- name: HACS Action
uses: hacs/action@main
uses: wuwentao/hacs_action@main
with:
category: "integration"
ignore: "brands"

- name: Hassfest validation
uses: "home-assistant/actions/hassfest@master"
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ config/
#Sensitive files
sensitive/

#exclude
custom_components/midea_ac_lan/midea/devices/b2/
Wcustom_components/midea_ac_lan/midea/devices/b7/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -106,7 +102,7 @@ celerybeat.pid
.env
.venv
env/
custom_components/midea_ac_lan/venv/
custom_components/midea_lan/venv/
ENV/
env.bak/
venv.bak/
Expand All @@ -123,8 +119,6 @@ venv.bak/
# Rope project settings
.ropeproject



# Pyre type checker
.pyre/

Expand All @@ -136,4 +130,4 @@ test.py
cloud_extend.py

# todo list
TODO.md
TODO.md
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repos:
hooks:
- id: codespell
args: ["-L hass,lookin,nam", "-w"]
exclude: "custom_components/midea_ac_lan/translations/de.json" # only de.json can't work with codespell
exclude: "custom_components/midea_lan/translations/de.json" # only de.json can't work with codespell
- repo: local
hooks:
- id: mypy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import homeassistant.helpers.config_validation as cv
import homeassistant.helpers.device_registry as dr
import homeassistant.helpers.entity_registry as er
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
Expand All @@ -28,7 +29,7 @@
MAJOR_VERSION,
MINOR_VERSION,
)
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import ConfigType
from midealocal.device import DeviceType, ProtocolVersion
from midealocal.devices import device_selector
Expand Down Expand Up @@ -278,6 +279,31 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->

_LOGGER.debug("Migration to configuration version 2 successful")

# 2 -> 3: migrate domain
if config_entry.version == 2: # noqa: PLR2004
_LOGGER.debug("Migrating configuration from version 2")

# Migrate config entry
new_data = {**config_entry.data}
new_data["domain"] = DOMAIN
if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 3):
hass.config_entries.async_update_entry(config_entry, version=2)
else:
config_entry.version = 2
hass.config_entries.async_update_entry(config_entry)

# Migrate device.
await _async_migrate_device_identifiers(hass, config_entry)

# Migrate entities.
await er.async_migrate_entries(
hass,
config_entry.entry_id,
_migrate_entities_domain,
)

_LOGGER.debug("Migration to configuration version 3 successful")

return True


Expand Down Expand Up @@ -316,3 +342,9 @@ async def _async_migrate_device_identifiers(
# Leave outer for loop if device entry is already found.
if device_entry_found:
break


@callback
def _migrate_entities_domain(entity_entry: er.RegistryEntry) -> dict[str, Any]: # noqa: ARG001
"""Migrate entities domain to the new name."""
return {"platform": DOMAIN}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MideaLanConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call-arg]
ConfigFlow will manage the creation of entries from user input, discovery
"""

VERSION = 2
VERSION = 3
MINOR_VERSION = 1

def __init__(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from homeassistant.const import Platform

DOMAIN = "midea_ac_lan"
DOMAIN = "midea_lan"
COMPONENT = "component"
DEVICES = "devices"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"domain": "midea_ac_lan",
"name": "Midea AC LAN",
"domain": "midea_lan",
"name": "Midea LAN",
"codeowners": ["@wuwentao", "@rokam", "@chemelli74", "@Necroneco"],
"config_flow": true,
"dependencies": [],
Expand Down
10 changes: 5 additions & 5 deletions doc/26.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ No Default entity

## Service

### midea_ac_lan.set_attribute
### midea_lan.set_attribute

[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_ac_lan.set_attribute)
[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_lan.set_attribute)

Set the attribute of appliance. Service data:

Expand All @@ -52,23 +52,23 @@ Set the attribute of appliance. Service data:
Example

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: main_light
value: true
```

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: mode
value: Bath
```

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: direction
Expand Down
10 changes: 5 additions & 5 deletions doc/26_hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

## 服务

### midea_ac_lan.set_attribute
### midea_lan.set_attribute

[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_ac_lan.set_attribute)
[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_lan.set_attribute)

设置设备属性, 服务数据:

Expand All @@ -52,23 +52,23 @@
示例

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: main_light
value: true
```

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: mode
value: Bath
```

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: direction
Expand Down
6 changes: 3 additions & 3 deletions doc/34.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ No default entity

## Service

### midea_ac_lan.set_attribute
### midea_lan.set_attribute

[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_ac_lan.set_attribute)
[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_lan.set_attribute)

Set the attribute of appliance. Service data:

Expand All @@ -46,7 +46,7 @@ Set the attribute of appliance. Service data:
Example

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: power
Expand Down
6 changes: 3 additions & 3 deletions doc/34_hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

## 服务

### midea_ac_lan.set_attribute
### midea_lan.set_attribute

[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_ac_lan.set_attribute)
[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_lan.set_attribute)

设置设备属性, 服务数据:

Expand All @@ -46,7 +46,7 @@
示例

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: power
Expand Down
8 changes: 4 additions & 4 deletions doc/40.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

## Services

### midea_ac_lan.set_attribute
### midea_lan.set_attribute

[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_ac_lan.set_attribute)
[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_lan.set_attribute)

Set the attribute of appliance. Service data:

Expand All @@ -46,15 +46,15 @@ Set the attribute of appliance. Service data:
Example

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: light
value: true
```

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: directions
Expand Down
8 changes: 4 additions & 4 deletions doc/40_hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

## 服务

### midea_ac_lan.set_attribute
### midea_lan.set_attribute

[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_ac_lan.set_attribute)
[![Service](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=midea_lan.set_attribute)

设置设备属性, 服务数据:

Expand All @@ -46,15 +46,15 @@
示例

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: light
value: true
```

```yaml
service: midea_ac_lan.set_attribute
service: midea_lan.set_attribute
data:
device_id: XXXXXXXXXXXX
attribute: directions
Expand Down
Loading
Loading