-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Qwikswitch sensors #13622
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
Merged
Merged
Qwikswitch sensors #13622
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,64 +6,56 @@ | |
| """ | ||
| import logging | ||
|
|
||
| from homeassistant.components.qwikswitch import DOMAIN as QWIKSWITCH | ||
| from homeassistant.helpers.entity import Entity | ||
| from homeassistant.components.qwikswitch import DOMAIN as QWIKSWITCH, QSEntity | ||
|
|
||
| DEPENDENCIES = [QWIKSWITCH] | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def async_setup_platform(hass, _, add_devices, discovery_info=None): | ||
| """Add lights from the main Qwikswitch component.""" | ||
| """Add sensor from the main Qwikswitch component.""" | ||
| if discovery_info is None: | ||
| return | ||
|
|
||
| qsusb = hass.data[QWIKSWITCH] | ||
| _LOGGER.debug("Setup qwikswitch.sensor %s, %s", qsusb, discovery_info) | ||
| devs = [QSSensor(name, qsid) | ||
| for name, qsid in discovery_info[QWIKSWITCH].items()] | ||
| devs = [QSSensor(sensor) for sensor in discovery_info[QWIKSWITCH]] | ||
| add_devices(devs) | ||
|
|
||
|
|
||
| class QSSensor(Entity): | ||
| class QSSensor(QSEntity): | ||
| """Sensor based on a Qwikswitch relay/dimmer module.""" | ||
|
|
||
| _val = {} | ||
| _val = None | ||
|
|
||
| def __init__(self, sensor_name, sensor_id): | ||
| def __init__(self, sensor): | ||
| """Initialize the sensor.""" | ||
| self._name = sensor_name | ||
| self.qsid = sensor_id | ||
| from pyqwikswitch import SENSORS | ||
|
|
||
| super().__init__(sensor['id'], sensor['name']) | ||
| self.channel = sensor['channel'] | ||
| self.sensor_type = sensor['type'] | ||
|
|
||
| self._decode, self.unit = SENSORS[self.sensor_type] | ||
| if isinstance(self.unit, type): | ||
| self.unit = "{}:{}".format(self.sensor_type, self.channel) | ||
|
|
||
| def update_packet(self, packet): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| """Receive update packet from QSUSB.""" | ||
| _LOGGER.debug("Update %s (%s): %s", self.entity_id, self.qsid, packet) | ||
| self._val = packet | ||
| self.async_schedule_update_ha_state() | ||
| val = self._decode(packet.get('data'), channel=self.channel) | ||
| _LOGGER.debug("Update %s (%s) decoded as %s: %s: %s", | ||
| self.entity_id, self.qsid, val, self.channel, packet) | ||
| if val is not None: | ||
| self._val = val | ||
| self.async_schedule_update_ha_state() | ||
|
|
||
| @property | ||
| def state(self): | ||
| """Return the value of the sensor.""" | ||
| return self._val.get('data', 0) | ||
|
|
||
| @property | ||
| def device_state_attributes(self): | ||
| """Return the state attributes of the sensor.""" | ||
| return self._val | ||
| return str(self._val) | ||
|
|
||
| @property | ||
| def unit_of_measurement(self): | ||
| """Return the unit the value is expressed in.""" | ||
| return None | ||
|
|
||
| @property | ||
| def poll(self): | ||
| """QS sensors gets packets in update_packet.""" | ||
| return False | ||
|
|
||
| async def async_added_to_hass(self): | ||
| """Listen for updates from QSUSb via dispatcher.""" | ||
| # Part of Entity/ToggleEntity | ||
| self.hass.helpers.dispatcher.async_dispatcher_connect( | ||
| self.qsid, self.update_packet) | ||
| return self.unit | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ | |
| 'pylitejet', | ||
| 'pymonoprice', | ||
| 'pynx584', | ||
| 'pyqwikswitch', | ||
| 'python-forecastio', | ||
| 'pyunifi', | ||
| 'pywebpush', | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be decorated with
@callbackimported from core.py.