Skip to content

Commit 9705abf

Browse files
committed
New class for Toshiba
1 parent 1737023 commit 9705abf

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

midealocal/cloud.py

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"api_url": "https://mapp.appsmb.com", # codespell:ignore
7373
},
7474
"Toshiba Iolife": {
75-
"class_name": "MideaAirCloud",
75+
"class_name": "ToshibaIOLife",
7676
"app_id": "1203",
7777
"app_key": "09c4d09f0da1513bb62dc7b6b0af9c11",
7878
"api_url": "https://toshiba-app.smartmidea.net", # codespell:ignore
@@ -842,6 +842,107 @@ async def list_appliances(
842842
return None
843843

844844

845+
class ToshibaIOLife(MideaAirCloud):
846+
""" Toshiba IOLife """
847+
async def list_appliance_types(
848+
self,
849+
) -> dict[int, dict[str, Any]] | None:
850+
""" List Toshiba IOLife device types """
851+
data = self._make_general_data()
852+
data.update({"applianceType": "0xFF"})
853+
if response := await self._api_request(
854+
endpoint="/v1/appliance/type/list/get",
855+
data=data,
856+
):
857+
return(data)
858+
return None
859+
860+
async def list_appliances(
861+
self,
862+
) -> dict[int, dict[str, Any]] | None:
863+
""" Get Toshiba IOLife devices."""
864+
data = self._make_general_data()
865+
if response := await self._api_request(
866+
endpoint="/v2/appliance/user/list/get",
867+
data=data,
868+
):
869+
appliances = {}
870+
for appliance in response["list"]:
871+
try:
872+
model_number = int(appliance.get("modelNumber", 0))
873+
except ValueError:
874+
model_number = 0
875+
876+
# Skip virtual batch devices:
877+
if appliance.get("type") == "0x_BATCH_AC":
878+
continue
879+
if appliance.get("id") == "virtual_ag_0xAC":
880+
continue
881+
device_info = {
882+
"name": appliance.get("name"),
883+
"type": int(appliance.get("type"), 16),
884+
"sn": appliance.get("sn"),
885+
"sn8": "",
886+
"model_number": model_number,
887+
"manufacturer_code": appliance.get("enterpriseCode", "0000"),
888+
"model": "",
889+
"online": appliance.get("onlineStatus") == "1",
890+
}
891+
serial_num = device_info.get("sn")
892+
device_info["sn8"] = (
893+
serial_num[9:17]
894+
if (serial_num and len(serial_num) > SN8_MIN_SERIAL_LENGTH)
895+
else ""
896+
)
897+
device_info["model"] = device_info.get("sn8")
898+
appliances[int(appliance["id"])] = device_info
899+
return appliances
900+
return None
901+
902+
903+
# FIXME: this isn't working:
904+
async def download_lua(
905+
self,
906+
path: str,
907+
device_type: int,
908+
sn: str,
909+
model_number: str | None = None,
910+
manufacturer_code: str = "0000",
911+
) -> str | None:
912+
"""Download lua integration."""
913+
data = self._make_general_data()
914+
data.update(
915+
{
916+
"appId": self._app_id,
917+
"appKey": self._app_key,
918+
"applianceMFCode": manufacturer_code,
919+
"applianceType": hex(device_type),
920+
"modelNumber": "",
921+
"applianceSn": sn,
922+
"version": "0",
923+
})
924+
if model_number is not None:
925+
data["modelNumber"] = model_number
926+
fnm = None
927+
if response := await self._api_request(
928+
endpoint="/v1/appliance/protocol/lua/luaGet", # FIXME: Wrong URL?
929+
data=data,
930+
):
931+
res = await self._session.get(response["url"])
932+
if res.status == HTTPStatus.OK:
933+
lua = await res.text()
934+
if lua:
935+
stream = (
936+
'local bit = require "bit"\n'
937+
+ self._security.aes_decrypt_with_fixed_key(lua)
938+
)
939+
stream = stream.replace("\r\n", "\n")
940+
fnm = f"{path}/{response['fileName']}"
941+
async with aiofiles.open(fnm, "w") as fp:
942+
await fp.write(stream)
943+
return str(fnm) if fnm else None
944+
945+
845946
def get_midea_cloud(
846947
cloud_name: str,
847948
session: ClientSession,

0 commit comments

Comments
 (0)