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

TG Electro motion sensor #2900

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions custom_components/tuya_local/devices/tg_electro_motion_sensor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: TG ELECTRO Smart motion sensor
products:
- id: ksxoagx7y6gsypck
model: TG-MS-PIR-S201
entities:
- entity: switch
translation_key: pir_sensor
icon: "mdi:cog"
dps:
- id: 51
type: string
name: switch
mapping:
- dps_val: auto
value: true
- dps_val: manual
value: false
- entity: light
dps:
- id: 20
type: boolean
name: switch
- entity: switch
translation_key: scanning
icon: "mdi:radar"
category: config
dps:
- id: 56
type: boolean
name: switch
- entity: select
translation_key: ambient_light
icon: "mdi:theme-light-dark"
class: illuminance
category: config
dps:
- id: 53
type: string
name: option
mapping:
- dps_val: 5lux
value: dark
- dps_val: 10lux
value: late_evening
- dps_val: 50lux
value: evening
- dps_val: 300lux
value: early_evening
- dps_val: 2000lux
value: day
- entity: select
translation_key: sensitivity
icon: "mdi:signal-distance-variant"
category: config
dps:
- id: 54
type: string
name: option
mapping:
- dps_val: low
value: low
- dps_val: middle
value: middle
- dps_val: high
value: high
- entity: number
translation_key: light_duration
icon: "mdi:timer-star"
class: duration
category: config
dps:
- id: 55
type: integer
name: value
unit: s
mode: slider
range:
min: 5
max : 360
- entity: binary_sensor
translation_key: status
icon: "mdi:access-point"
category: diagnostic
dps:
- id: 52
type: string
name: sensor
mapping:
- dps_val: none
value: true
- dps_val: motion
value: false
30 changes: 30 additions & 0 deletions custom_components/tuya_local/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
}
}
}
},
"status":{
"name": "Status"
}
},
"button": {
Expand Down Expand Up @@ -382,6 +385,9 @@
},
"timer_x": {
"name": "Timer {x}"
},
"light_duration": {
"name": "Light duration"
}
},
"select": {
Expand Down Expand Up @@ -551,6 +557,24 @@
"red_bean_bread": "Red Bean Bread",
"milk_toast": "Milk Toast"
}
},
"ambient_light": {
"name": "Ambient light",
"state": {
"dark": "Night",
"late_evening": "Late evening",
"evening": "Evening",
"early_evening": "Early evening",
"day": "Day"
}
},
"sensitivity": {
"name": "Sensitivity",
"state": {
"low": "Low",
"middle": "Medium",
"high": "High"
}
}
},
"sensor": {
Expand Down Expand Up @@ -701,6 +725,12 @@
"switch_x": {
"name": "Switch {x}"
},
"pir_sensor": {
"name": "PIR sensor"
},
"scanning": {
"name": "Scanning"
},
"uv_sterilization": {
"name": "UV sterilization"
},
Expand Down
30 changes: 30 additions & 0 deletions custom_components/tuya_local/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
}
}
}
},
"status":{
"name": "Status"
}
},
"button": {
Expand Down Expand Up @@ -382,6 +385,9 @@
},
"timer_x": {
"name": "Regulator czasowy {x}"
},
"light_duration": {
"name": "Czas oświetlenia"
}
},
"select": {
Expand Down Expand Up @@ -552,6 +558,24 @@
"red_bean_bread": "Chleb z czerwoną fasolą",
"milk_toast": "Mleczny tost"
}
},
"ambient_light": {
"name": "Jasność otoczenia",
"state": {
"dark": "Noc",
"late_evening": "Wieczór",
"evening": "Zmierzch",
"early_evening": "Wczesny zmierzch",
"day": "Dzień"
}
},
"sensitivity": {
"name": "Czułość",
"state": {
"low": "Niska",
"middle": "Średnia",
"high": "Wysoka"
}
}
},
"sensor": {
Expand Down Expand Up @@ -702,6 +726,12 @@
"switch_x": {
"name": "Przełącznik {x}"
},
"pir_sensor": {
"name": "Czujnik PIR"
},
"scanning": {
"name": "Skanowanie"
},
"electrolytic_sterilization": {
"name": "Elektrolityczna sterylizacja"
},
Expand Down
8 changes: 8 additions & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,14 @@
"110": 0,
}

TG_ELECTRO_SENSOR_PAYLOAD = {
"51": "auto",
"20": False,
"53": "10lux",
"54": "middle",
"55": 60,
}

HYDROTHERM_DYNAMICX8_PAYLOAD = {
"1": True,
"2": 65,
Expand Down
91 changes: 91 additions & 0 deletions tests/devices/test_tg_electro_motion_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from homeassistant.components.number.const import NumberDeviceClass
from homeassistant.const import UnitOfTime

from ..const import TG_ELECTRO_SENSOR_PAYLOAD
from ..helpers import assert_device_properties_set

Check failure on line 5 in tests/devices/test_tg_electro_motion_sensor.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

tests/devices/test_tg_electro_motion_sensor.py:5:23: F401 `..helpers.assert_device_properties_set` imported but unused
from ..mixins.select import MultiSelectTests
from ..mixins.number import MultiNumberTests
from ..mixins.switch import BasicSwitchTests
from .base_device_tests import TuyaDeviceTestCase

PIR_SENSOR_DPS = "51"
SWITCH_DPS = "20"
LUX_DPS = "53"
PROX_DPS = "54"
TIME_DPS = "55"


class TestMotionLight(BasicSwitchTests, MultiSelectTests, MultiNumberTests, TuyaDeviceTestCase):
__test__ = True

def setUp(self):
self.setUpForConfig("tg_electro_motion_sensor.yaml", TG_ELECTRO_SENSOR_PAYLOAD)
self.subject = self.entities.get("light")
self.auto_sw = self.entities.get("switch_pir_sensor")
self.setUpMultiSelect(
[
{
"dps": LUX_DPS,
"name": "select_ambient_light",
"options": {
"5lux": "dark",
"10lux": "late_evening",
"50lux": "evening",
"300lux": "early_evening",
"2000lux": "day",
}
},
{
"dps": PROX_DPS,
"name": "select_sensitivity",
"options": {
"low": "low",
"middle": "middle",
"high": "high"
}
}
]
)
self.setUpMultiNumber(
[
{
"dps": TIME_DPS,
"name": "number_light_duration",
"device_class": NumberDeviceClass.DURATION,
"min": 5,
"max": 360,
"step": 10,
"unit": UnitOfTime.SECONDS,
}
]
)
self.mark_secondary(
[
"number_light_duration",
"select_ambient_light",
"select_sensitivity",
]
)

def test_is_on_reflects_switch(self):
self.dps[SWITCH_DPS] = True
self.assertTrue(self.subject.is_on)
self.dps[SWITCH_DPS] = False
self.assertFalse(self.subject.is_on)

def test_auto_mode_is_on(self):
self.dps[SWITCH_DPS] = False
self.dps[PIR_SENSOR_DPS] = "auto"
self.assertTrue(self.auto_sw.is_on)
self.assertFalse(self.subject.is_on)
self.dps[PIR_SENSOR_DPS] = "manual"
self.assertFalse(self.auto_sw.is_on)
self.assertFalse(self.subject.is_on)
self.dps[SWITCH_DPS] = True
self.dps[PIR_SENSOR_DPS] = "auto"
self.assertTrue(self.auto_sw.is_on)
self.assertTrue(self.subject.is_on)
self.dps[PIR_SENSOR_DPS] = "manual"
self.assertFalse(self.auto_sw.is_on)
self.assertTrue(self.subject.is_on)

Loading