Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Removed a little duplication #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 7 additions & 8 deletions sonoff/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,22 @@ def is_on(self):
self._state = self.get_state()
return self._state

def turn_on(self, **kwargs):
def change_state(self, new_state, **kwargs):
"""Turn the device on."""
self._hass.bus.async_fire('sonoff_state', {
'state' : True,
'state' : new_state,
'deviceid' : self._deviceid,
'outlet' : self._outlet
})
self.async_schedule_update_ha_state()

def turn_on(self, **kwargs):
"""Turn the device on."""
self.change_state(True, **kwargs)

def turn_off(self, **kwargs):
"""Turn the device off."""
self._hass.bus.async_fire('sonoff_state', {
'state' : False,
'deviceid' : self._deviceid,
'outlet' : self._outlet
})
self.async_schedule_update_ha_state()
self.change_state(False, **kwargs)

# entity id is required if the name use other characters not in ascii
@property
Expand Down