Skip to content

Commit

Permalink
Merge pull request #499 from krahabb/dev
Browse files Browse the repository at this point in the history
Moonlight.4.0
  • Loading branch information
krahabb authored Oct 10, 2024
2 parents 881e365 + 71373b7 commit 0becc23
Show file tree
Hide file tree
Showing 32 changed files with 1,949 additions and 525 deletions.
8 changes: 0 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
"files.associations": {
"*.yaml": "home-assistant"
},
"python.analysis.typeCheckingMode": "basic",
"python.analysis.diagnosticSeverityOverrides": {
"reportPrivateImportUsage": "none",
"reportShadowedImports": "none"
},
"python.analysis.extraPaths": [
"./custom_components/meross_lan"
],
"testing.defaultGutterClickAction": "debug",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/meross_lan/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def async_turn_on(self):
async def async_turn_off(self):
await self.async_request_onoff(0)

async def async_set_hvac_mode(self, hvac_mode: "MtsClimate.HVACMode"):
async def async_set_hvac_mode(self, hvac_mode: climate.HVACMode):
raise NotImplementedError()

async def async_set_preset_mode(self, preset_mode: str):
Expand Down
17 changes: 14 additions & 3 deletions custom_components/meross_lan/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import logging
from time import time
from types import MappingProxyType
import typing

from homeassistant import config_entries as ce, const as hac
Expand All @@ -15,7 +16,12 @@
import voluptuous as vol

from . import MerossApi, const as mlc
from .helpers import ConfigEntriesHelper, ConfigEntryType, reverse_lookup
from .helpers import (
ConfigEntriesHelper,
ConfigEntryType,
get_default_no_verify_ssl_context,
reverse_lookup,
)
from .helpers.manager import CloudApiClient
from .merossclient import (
HostAddress,
Expand Down Expand Up @@ -320,7 +326,8 @@ async def async_step_profile(self, user_input=None):
# this patch is the best I can think of
ce.ConfigEntry(
version=self.VERSION,
minor_version=self.MINOR_VERSION, # type: ignore
minor_version=self.MINOR_VERSION, # required since 2024.1
discovery_keys=MappingProxyType({}), # required since 2024.10
domain=mlc.DOMAIN,
title=profile_config[mc.KEY_EMAIL],
data=profile_config,
Expand Down Expand Up @@ -1238,7 +1245,11 @@ async def async_step_bind(self, user_input=None):
key = key or api.key or ""
userid = "" if userid is None else str(userid)
mqttclient = MerossMQTTDeviceClient(
device.id, key=key, userid=userid, loop=hass.loop
device.id,
key=key,
userid=userid,
loop=hass.loop,
sslcontext=get_default_no_verify_ssl_context(),
)
if api.isEnabledFor(api.VERBOSE):
mqttclient.enable_logger(api) # type: ignore (Loggable is duck-compatible with Logger)
Expand Down
2 changes: 2 additions & 0 deletions custom_components/meross_lan/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class ProfileConfigType(
"""used when polling the cover state to monitor an ongoing transition"""
PARAM_CLOUDMQTT_UPDATE_PERIOD = 1795
"""for polled entities over cloud MQTT use 'at least' this"""
PARAM_CONFIG_UPDATE_PERIOD = 300
"""read device config polling period"""
PARAM_DIAGNOSTIC_UPDATE_PERIOD = 300
"""read diagnostic sensors only every ... second"""
PARAM_ENERGY_UPDATE_PERIOD = 55
Expand Down
Empty file.
31 changes: 14 additions & 17 deletions custom_components/meross_lan/devices/diffuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
)
from ..meross_entity import MEListChannelMixin
from ..merossclient import const as mc, namespaces as mn
from ..sensor import MLHumiditySensor, MLTemperatureSensor
from ..sensor import MLHumiditySensor, MLNumericSensorDef, MLTemperatureSensor
from .spray import MLSpray

if typing.TYPE_CHECKING:
from ..meross_device import DigestInitReturnType, MerossDevice
from ..sensor import MLNumericSensor


DIFFUSER_SENSOR_CLASS_MAP: dict[
str, type[MLHumiditySensor] | type[MLTemperatureSensor]
] = {
mc.KEY_HUMIDITY: MLHumiditySensor,
mc.KEY_TEMPERATURE: MLTemperatureSensor,
DIFFUSER_SENSOR_CLASS_MAP: dict[str, MLNumericSensorDef] = {
mc.KEY_HUMIDITY: MLNumericSensorDef(MLHumiditySensor, {}),
mc.KEY_TEMPERATURE: MLNumericSensorDef(MLTemperatureSensor, {"device_scale": 10}),
}


Expand Down Expand Up @@ -68,16 +67,14 @@ def _handle_Appliance_Control_Diffuser_Sensor(header: dict, payload: dict):
}
"""
entities = device.entities
for key in (mc.KEY_HUMIDITY, mc.KEY_TEMPERATURE):
for key in DIFFUSER_SENSOR_CLASS_MAP:
if key in payload:
try:
entities[key].update_native_value(
payload[key][mc.KEY_VALUE] / 10
)
entity: MLNumericSensor = entities[key] # type: ignore
except KeyError:
DIFFUSER_SENSOR_CLASS_MAP[key](
device, None, device_value=payload[key][mc.KEY_VALUE] / 10
)
entity_def = DIFFUSER_SENSOR_CLASS_MAP[key]
entity = entity_def.type(device, None, key, **entity_def.args)
entity.update_device_value(payload[key][mc.KEY_VALUE])

NamespaceHandler(
device,
Expand Down Expand Up @@ -191,8 +188,8 @@ class MLDiffuserSpray(MEListChannelMixin, MLSpray):

ns = mn.Appliance_Control_Diffuser_Spray

SPRAY_MODE_MAP = {
mc.DIFFUSER_SPRAY_MODE_OFF: MLSpray.OPTION_SPRAY_MODE_OFF,
mc.DIFFUSER_SPRAY_MODE_ECO: MLSpray.OPTION_SPRAY_MODE_ECO,
mc.DIFFUSER_SPRAY_MODE_FULL: MLSpray.OPTION_SPRAY_MODE_CONTINUOUS,
OPTIONS_MAP = {
mc.DIFFUSER_SPRAY_MODE_OFF: MLSpray.OPTIONS_MAP[mc.SPRAY_MODE_OFF],
mc.DIFFUSER_SPRAY_MODE_ECO: MLSpray.OPTIONS_MAP[mc.SPRAY_MODE_INTERMITTENT],
mc.DIFFUSER_SPRAY_MODE_FULL: MLSpray.OPTIONS_MAP[mc.SPRAY_MODE_CONTINUOUS],
}
Loading

0 comments on commit 0becc23

Please sign in to comment.