Skip to content

Commit

Permalink
Cleanup, updated
Browse files Browse the repository at this point in the history
  • Loading branch information
aneisch committed Apr 1, 2023
1 parent 2b6e261 commit 381e85e
Show file tree
Hide file tree
Showing 27 changed files with 1,188 additions and 662 deletions.
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,52 +57,51 @@ Also using Grafana/Influx for graphing, both running in Docker containers on NUC
## Some statistics about my installation:
Description | value
-- | --
Lines of ESPHome YAML | 2378
Lines of Home Assistant YAML | 7070
[Integrations](https://www.home-assistant.io/integrations/) in use | 45
Lines of ESPHome YAML | 2380
Lines of Home Assistant YAML | 7080
[Integrations](https://www.home-assistant.io/integrations/) in use | 44
Zigbee devices in [`zha`](https://www.home-assistant.io/integrations/zha/) | 26
Z-Wave devices in [`zwave_js`](https://www.home-assistant.io/integrations/zwave_js/) | 37

Description | value
-- | --
Entities in the [`alarm_control_panel`](https://www.home-assistant.io/components/alarm_control_panel) domain | 3
Entities in the [`automation`](https://www.home-assistant.io/components/automation) domain | 104
Entities in the [`binary_sensor`](https://www.home-assistant.io/components/binary_sensor) domain | 100
Entities in the [`automation`](https://www.home-assistant.io/components/automation) domain | 86
Entities in the [`binary_sensor`](https://www.home-assistant.io/components/binary_sensor) domain | 87
Entities in the [`button`](https://www.home-assistant.io/components/button) domain | 64
Entities in the [`calendar`](https://www.home-assistant.io/components/calendar) domain | 1
Entities in the [`camera`](https://www.home-assistant.io/components/camera) domain | 15
Entities in the [`climate`](https://www.home-assistant.io/components/climate) domain | 1
Entities in the [`counter`](https://www.home-assistant.io/components/counter) domain | 1
Entities in the [`cover`](https://www.home-assistant.io/components/cover) domain | 5
Entities in the [`device_tracker`](https://www.home-assistant.io/components/device_tracker) domain | 26
Entities in the [`device_tracker`](https://www.home-assistant.io/components/device_tracker) domain | 4
Entities in the [`fan`](https://www.home-assistant.io/components/fan) domain | 3
Entities in the [`group`](https://www.home-assistant.io/components/group) domain | 13
Entities in the [`input_boolean`](https://www.home-assistant.io/components/input_boolean) domain | 27
Entities in the [`input_datetime`](https://www.home-assistant.io/components/input_datetime) domain | 32
Entities in the [`input_number`](https://www.home-assistant.io/components/input_number) domain | 5
Entities in the [`input_boolean`](https://www.home-assistant.io/components/input_boolean) domain | 24
Entities in the [`input_datetime`](https://www.home-assistant.io/components/input_datetime) domain | 31
Entities in the [`input_number`](https://www.home-assistant.io/components/input_number) domain | 4
Entities in the [`input_select`](https://www.home-assistant.io/components/input_select) domain | 19
Entities in the [`input_text`](https://www.home-assistant.io/components/input_text) domain | 7
Entities in the [`input_text`](https://www.home-assistant.io/components/input_text) domain | 4
Entities in the [`light`](https://www.home-assistant.io/components/light) domain | 38
Entities in the [`lock`](https://www.home-assistant.io/components/lock) domain | 2
Entities in the [`media_player`](https://www.home-assistant.io/components/media_player) domain | 13
Entities in the [`media_player`](https://www.home-assistant.io/components/media_player) domain | 12
Entities in the [`number`](https://www.home-assistant.io/components/number) domain | 55
Entities in the [`person`](https://www.home-assistant.io/components/person) domain | 2
Entities in the [`plant`](https://www.home-assistant.io/components/plant) domain | 1
Entities in the [`remote`](https://www.home-assistant.io/components/remote) domain | 1
Entities in the [`scene`](https://www.home-assistant.io/components/scene) domain | 2
Entities in the [`script`](https://www.home-assistant.io/components/script) domain | 46
Entities in the [`select`](https://www.home-assistant.io/components/select) domain | 22
Entities in the [`sensor`](https://www.home-assistant.io/components/sensor) domain | 381
Entities in the [`script`](https://www.home-assistant.io/components/script) domain | 37
Entities in the [`select`](https://www.home-assistant.io/components/select) domain | 20
Entities in the [`sensor`](https://www.home-assistant.io/components/sensor) domain | 335
Entities in the [`setter`](https://www.home-assistant.io/components/setter) domain | 1
Entities in the [`siren`](https://www.home-assistant.io/components/siren) domain | 1
Entities in the [`sun`](https://www.home-assistant.io/components/sun) domain | 1
Entities in the [`switch`](https://www.home-assistant.io/components/switch) domain | 157
Entities in the [`switch`](https://www.home-assistant.io/components/switch) domain | 152
Entities in the [`timer`](https://www.home-assistant.io/components/timer) domain | 1
Entities in the [`update`](https://www.home-assistant.io/components/update) domain | 25
Entities in the [`vacuum`](https://www.home-assistant.io/components/vacuum) domain | 1
Entities in the [`weather`](https://www.home-assistant.io/components/weather) domain | 2
Entities in the [`zone`](https://www.home-assistant.io/components/zone) domain | 6
**Total state objects** | **1184**
**Total state objects** | **1059**
## The HACS integrations/plugins that I use:
**Appdaemon**:<br>
[aneisch/follow_me_appdaemon](https://github.com/aneisch/follow_me_appdaemon)<br>
Expand Down
84 changes: 42 additions & 42 deletions configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ folder_watcher:
- folder: /tmp
use_polling: True
patterns:
- 'database.sqlite'
- "database.sqlite"

monitor_docker:
#scan_interval: 60
Expand Down Expand Up @@ -163,7 +163,7 @@ light:
# port: 8899
# groups:
# # big bulbs
# #- number: 1
# #- number: 1
# # type: rgbw
# # name: Garage
# # fade: on
Expand Down Expand Up @@ -214,42 +214,42 @@ logger:
#default: debug
default: warn
#logs:
#homeassistant.core: debug
#homeassistant.components.python_script: debug
#custom_components.alexa_media: debug
# Start ZHA Debugging
# asyncio: debug
#homeassistant.components.zha: debug
#zigpy: debug
# bellows: debug
# zigpy_xbee: debug
# zigpy_deconz: debug
# zigpy_zigate: debug
# zigpy_cc: debug
# bellows.zigbee.application: debug
# bellows.ezsp: debug
# zigpy_deconz.zigbee.application: debug
# zigpy_deconz.api: debug
# zigpy_xbee.ap: debug
# zigpy_znp: debug
# zhaquirks: debug
# End ZHA Debugging
#custom_components.docker_monitor: debug
#custom_components.alexa_media: debug
#custom_components.localtuya: debug
#homeassistant.components.webhook: debug
#custom_components.mail_and_packages: debug
# custom_components.aarlo: debug
# custom_components.aarlo.alarm_control_panel: debug
# custom_components.aarlo.binary_sensor: debug
# custom_components.aarlo.camera: debug
# custom_components.aarlo.light: debug
# custom_components.aarlo.media_player: debug
# custom_components.aarlo.sensor: debug
# custom_components.aarlo.switch: debug
# pyaarlo: debug
#custom_components.bhyve: debug
#pybhyve: debug
#homeassistant.core: debug
#homeassistant.components.python_script: debug
#custom_components.alexa_media: debug
# Start ZHA Debugging
# asyncio: debug
#homeassistant.components.zha: debug
#zigpy: debug
# bellows: debug
# zigpy_xbee: debug
# zigpy_deconz: debug
# zigpy_zigate: debug
# zigpy_cc: debug
# bellows.zigbee.application: debug
# bellows.ezsp: debug
# zigpy_deconz.zigbee.application: debug
# zigpy_deconz.api: debug
# zigpy_xbee.ap: debug
# zigpy_znp: debug
# zhaquirks: debug
# End ZHA Debugging
#custom_components.docker_monitor: debug
#custom_components.alexa_media: debug
#custom_components.localtuya: debug
#homeassistant.components.webhook: debug
#custom_components.mail_and_packages: debug
# custom_components.aarlo: debug
# custom_components.aarlo.alarm_control_panel: debug
# custom_components.aarlo.binary_sensor: debug
# custom_components.aarlo.camera: debug
# custom_components.aarlo.light: debug
# custom_components.aarlo.media_player: debug
# custom_components.aarlo.sensor: debug
# custom_components.aarlo.switch: debug
# pyaarlo: debug
#custom_components.bhyve: debug
#pybhyve: debug
filters:
homeassistant.core:
- ".*share-service-download-bucket.*" # Ring Video Updates
Expand All @@ -267,7 +267,7 @@ lovelace:
- url: /hacsfiles/weather-card/weather-card.js
type: module
- url: /hacsfiles/lovelace-slider-entity-row/slider-entity-row.js
type: js
type: module
- url: /hacsfiles/lovelace-hass-aarlo/hass-aarlo.js
type: module
- url: /hacsfiles/mini-media-player/mini-media-player-bundle.js
Expand All @@ -279,7 +279,7 @@ lovelace:
- url: /hacsfiles/favicon-counter/favicon-counter.js
type: module
- url: /hacsfiles/vertical-stack-in-card/vertical-stack-in-card.js
type: js
type: module
- url: /hacsfiles/zha-network-visualization-card/zha-network-visualization-card.js
type: module
- url: /hacsfiles/lovelace-card-templater/lovelace-card-templater.js
Expand Down Expand Up @@ -376,7 +376,7 @@ panel_iframe:
vscode:
title: VS Code
icon: mdi:wrench
url: !secret vscode_url
url: !secret vscode_url
plane_tracking:
title: "Plane Tracking"
icon: mdi:airplane
Expand Down Expand Up @@ -484,7 +484,7 @@ sonoff:
password: !secret ewelink_pass
mode: local
reload: always

stream:

sun:
Expand Down
12 changes: 10 additions & 2 deletions custom_components/sonoff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,20 @@ async def send_command(call: ServiceCall):
deviceid = str(params.pop("device"))

if len(deviceid) == 10:
registry = next(
registry: XRegistry = next(
r for r in hass.data[DOMAIN].values() if deviceid in r.devices
)
device = registry.devices[deviceid]

await registry.send(device, params)
# for debugging purposes
if v := params.get("set_device"):
device.update(v)
return

params_lan = params.pop("params_lan", None)
command_lan = params.pop("command_lan", None)

await registry.send(device, params, params_lan, command_lan)

elif len(deviceid) == 6:
await cameras.send(deviceid, params["cmd"])
Expand Down
4 changes: 3 additions & 1 deletion custom_components/sonoff/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ def internal_update(self, ts: str):

async def async_press(self):
await self.ewelink.send(
self.bridge, {"cmd": "transmit", "rfChl": int(self.channel)}
self.bridge,
{"cmd": "transmit", "rfChl": int(self.channel)},
cmd_lan="transmit",
)
23 changes: 5 additions & 18 deletions custom_components/sonoff/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ..climate import XClimateNS, XClimateTH, XThermostat
from ..core.entity import XEntity
from ..cover import XCover, XCoverDualR3, XZigbeeCover
from ..fan import XDiffuserFan, XFan, XToggleFan
from ..fan import XDiffuserFan, XFan, XToggleFan, XFanDualR3
from ..light import (
XDiffuserLight,
XDimmer,
Expand All @@ -34,6 +34,7 @@
XLightD1,
XLightGroup,
XLightL1,
XLightL3,
)
from ..number import XPulseWidth
from ..remote import XRemote
Expand All @@ -55,6 +56,7 @@
DEVICE_CLASS = {
"binary_sensor": (XEntity, BinarySensorEntity),
"fan": (XToggleFan,), # using custom class for overriding is_on function
"dualfan": (XFanDualR3,),
"light": (XEntity, LightEntity),
"sensor": (XEntity, SensorEntity),
"switch": (XEntity, SwitchEntity),
Expand Down Expand Up @@ -278,7 +280,7 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
165: [Switch1, Switch2, RSSI], # DualR3 Lite, without power consumption
# https://github.com/AlexxIT/SonoffLAN/issues/857
168: [RSSI], # new ZBBridge-P
173: [XLightL1, RSSI], # Sonoff L3-5M-P
173: [XLightL3, RSSI], # Sonoff L3-5M-P
174: [XRemoteButton], # Sonoff R5 (6-key remote)
177: [XRemoteButton], # Sonoff S-Mate
181: [
Expand Down Expand Up @@ -340,21 +342,6 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
],
}

# Pow devices sends sensors data via Cloud only in uiActive mode
# - Sonoff POW1 fw 2.6.1 UIID5 sends power data even without uiActive
# - Sonoff S40 fw 1.1.0 UIID182 has very low uiActive maximum
# - Sonoff DualR3 fw 1.4.0 UIID126 has another uiActive format
# UUID, refresh time in seconds, params payload
POW_UI_ACTIVE = {
5: (3600, {"uiActive": 7200}),
32: (3600, {"uiActive": 7200}),
126: (3600, {"uiActive": {"all": 1, "time": 7200}}),
130: (3600, {"uiActive": {"all": 1, "time": 7200}}),
182: (0, {"uiActive": 180}), # maximum for this model
# https://github.com/AlexxIT/SonoffLAN/issues/978
190: (0, {"uiActive": 180}), # haven't check real maximum
}


def get_spec(device: dict) -> list:
uiid = device["extra"]["uiid"]
Expand All @@ -371,7 +358,7 @@ def get_spec(device: dict) -> list:
# DualR3 in cover mode
if uiid in [126, 165] and device["params"].get("workMode") == 2:
classes = [cls for cls in classes if XSwitches not in cls.__bases__]
classes.append(XCoverDualR3)
classes.insert(0, XCoverDualR3)

# NSPanel Climate disable without switch configuration
if uiid in [133] and not device["params"].get("HMI_ATCDevice"):
Expand Down
20 changes: 17 additions & 3 deletions custom_components/sonoff/core/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,19 @@ def __init__(self, ewelink: XRegistry, device: XDevice) -> None:
self.internal_update(params)
except Exception as e:
_LOGGER.error(f"Can't init device: {device}", exc_info=e)

ewelink.dispatcher_connect(deviceid, self.internal_update)

if parent := device.get("parent"):
ewelink.dispatcher_connect(parent["deviceid"], self.internal_parent_update)

def set_state(self, params: dict):
pass

def internal_available(self) -> bool:
return (self.ewelink.cloud.online and self.device.get("online")) or (
self.ewelink.local.online and "host" in self.device
device = self.device.get("parent") or self.device
return (self.ewelink.cloud.online and device.get("online")) or (
self.ewelink.local.online and device.get("local")
)

def internal_update(self, params: dict = None):
Expand All @@ -113,5 +118,14 @@ def internal_update(self, params: dict = None):
if change and self.hass:
self._async_write_ha_state()

def internal_parent_update(self, params: dict = None):
self.internal_update(None)

async def async_update(self):
await self.ewelink.send(self.device)
if led := self.device["params"].get("sledOnline"):
# device response with current status if we change any param
await self.ewelink.send(
self.device, params_lan={"sledOnline": led}, cmd_lan="sledonline"
)
else:
await self.ewelink.send(self.device)
Loading

0 comments on commit 381e85e

Please sign in to comment.