Skip to content

Commit

Permalink
Fix Sonoff TH fw 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Mar 9, 2020
1 parent a23d9a6 commit 1b44b08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Thanks to these people [@beveradb](https://github.com/beveradb/sonoff-lan-mode-h

- [Sonoff Basic](https://www.itead.cc/sonoff-wifi-wireless-switch.html) fw 3.0.1
- [Sonoff Mini](https://www.itead.cc/sonoff-mini.html) (no need use DIY-mode) fw 3.3.0
- [Sonoff TH](https://www.itead.cc/sonoff-th.html) (show temperature and humidity) **control don't work on fw 3.4.0!**
- [Sonoff TH](https://www.itead.cc/sonoff-th.html) (show temperature and humidity) fw 3.4.0
- [Sonoff 4CH Pro R2](https://www.itead.cc/sonoff-4ch-pro.html) fw 3.3.0
- [Sonoff Pow R2](https://www.itead.cc/sonoff-pow-r2.html) (show power consumption)
- [Sonoff Micro](https://www.itead.cc/sonoff-micro-5v-usb-smart-adaptor.html) fw 3.4.0
Expand Down
11 changes: 11 additions & 0 deletions custom_components/sonoff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ async def send(self, command: str, data: dict):
except:
_LOGGER.warning(f"Can't send {command} to {self.deviceid}")

@property
@lru_cache()
def is_th_3_4_0(self):
return self.state.get('deviceType') in ('normal', 'temperature')

async def turn_on(self, channels: Optional[list]):
"""Включает указанные каналы.
Expand All @@ -387,6 +392,9 @@ async def turn_on(self, channels: Optional[list]):
for channel in channels
]
await self.send('switches', {'switches': switches})
elif self.is_th_3_4_0:
await self.send('switch', {'switch': 'on', 'mainSwitch': 'on',
'deviceType': 'normal'})
else:
await self.send('switch', {'switch': 'on'})

Expand All @@ -401,6 +409,9 @@ async def turn_off(self, channels: Optional[list]):
for channel in channels
]
await self.send('switches', {'switches': switches})
elif self.is_th_3_4_0:
await self.send('switch', {'switch': 'off', 'mainSwitch': 'off',
'deviceType': 'normal'})
else:
await self.send('switch', {'switch': 'off'})

Expand Down

0 comments on commit 1b44b08

Please sign in to comment.