-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
Add LaCrosse sensor platform #10195
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
Add LaCrosse sensor platform #10195
Conversation
Signed-off-by: Heiko Thiery <[email protected]>
self._expiration_trigger = async_track_point_in_utc_time( | ||
self.hass, self.value_is_expired, expiration_at) | ||
|
||
self._temperature = round(lacrosse_sensor.temperature * 2) /2 |
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.
missing whitespace around operator
return self._name | ||
|
||
|
||
def update(self, *args): |
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.
too many blank lines (2)
self._expiration_trigger = None | ||
|
||
lacrosse.register_callback(int(self._config["id"]), | ||
self._callback_lacrosse, None) |
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.
continuation line under-indented for visual indent
expire_after, config): | ||
self.hass = hass | ||
self.entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, device_id, | ||
hass=hass) |
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.
continuation line over-indented for visual indent
_new_battery = None | ||
|
||
def __init__(self, hass, lacrosse, device_id, friendly_name, | ||
expire_after, config): |
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.
continuation line under-indented for visual indent
|
||
add_devices(sensors) | ||
|
||
def close_serial_port(*args): |
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.
expected 2 blank lines, found 1
) | ||
|
||
|
||
if not sensors: |
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.
too many blank lines (2)
|
||
lacrosse = None | ||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): |
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.
expected 2 blank lines, found 1
Signed-off-by: Heiko Thiery <[email protected]>
self._expiration_trigger = None | ||
|
||
lacrosse.register_callback(int(self._config["id"]), \ | ||
self._callback_lacrosse, None) |
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.
continuation line under-indented for visual indent
self._expire_after = expire_after | ||
self._expiration_trigger = None | ||
|
||
lacrosse.register_callback(int(self._config["id"]), \ |
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.
the backslash is redundant between brackets
def __init__(self, hass, lacrosse, device_id, friendly_name, \ | ||
expire_after, config): | ||
self.hass = hass | ||
self.entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, \ |
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.
the backslash is redundant between brackets
_new_battery = None | ||
|
||
def __init__(self, hass, lacrosse, device_id, friendly_name, \ | ||
expire_after, config): |
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.
continuation line under-indented for visual indent
_low_battery = None | ||
_new_battery = None | ||
|
||
def __init__(self, hass, lacrosse, device_id, friendly_name, \ |
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.
the backslash is redundant between brackets
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
|
||
|
||
|
||
class LaCrosseSensor(Entity): |
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.
too many blank lines (4)
Signed-off-by: Heiko Thiery <[email protected]>
Signed-off-by: Heiko Thiery <[email protected]>
Currently I cannot figure out why build fails. Has anyone an idea? |
Signed-off-by: Heiko Thiery <[email protected]>
def state(self): | ||
"""Return the state of the sensor.""" | ||
if self._low_battery is None: | ||
state = 'na/a' |
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.
I guess that is like None
.
return icon | ||
|
||
|
||
TYPE_CLASSES = { |
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.
Could you please move that to the file header.
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.
If I move this to the beginning of the file I get the following error;
NameError: name 'LaCrosseTemperature' is not defined.
So that was the reason to keep the dict at the end. Any suggestions how to handle this?
device_id, hass=hass) | ||
self._config = config | ||
self._name = friendly_name | ||
self._value = STATE_UNKNOWN |
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.
Set it to None
and let Home Assistant handle it.
|
||
usb_device = config.get(CONF_DEVICE, DEFAULT_DEVICE) | ||
baud = int(config.get(CONF_BAUD, DEFAULT_BAUD)) | ||
expire_after = config.get(CONF_EXPIRE_AFTER, DEFAULT_EXPIRE_AFTER) |
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.
The configuration validation is already setting the default.
SENSOR_SCHEMA = vol.Schema({ | ||
vol.Required(CONF_TYPE): vol.In(TYPES), | ||
vol.Required(CONF_ID): cv.positive_int, | ||
vol.Optional(CONF_FRIENDLY_NAME): cv.string, |
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.
Please use CONF_NAME
to be in sync with a bunch of other platforms.
|
||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
vol.Optional(CONF_DEVICE, default=DEFAULT_DEVICE): cv.string, | ||
vol.Optional(CONF_BAUD, default=DEFAULT_BAUD): cv.string, |
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.
You need something like vol.Required(CONF_SENSORS): vol.Schema({cv.slug: SENSOR_SCHEMA}),
in the platform validation.
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
DOMAIN = 'lacrosse' |
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.
Not used.
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Setup the LaCrosse component.""" |
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.
Must be something like """Set up the...
. Docstrings need to pass PEP257 validation.
Signed-off-by: Heiko Thiery <[email protected]>
try: | ||
sensor_class = TYPE_CLASSES[typ] | ||
except KeyError: | ||
_LOGGER.exception("Unknown LaCrosse sensor type: %s", typ) |
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.
Not needed as the validation only allows TYPES
.
Signed-off-by: Heiko Thiery <[email protected]>
Do I need to add tests for the PR? |
You could if you want. It's not a requirement as you depend on a module and often the module itself contains already tests. |
Ok that means I can remove the checkbox for tests from the checklist? |
Oh, you were talking about the local |
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.
Thanks 🐦
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.
If the devices use callbacks to update state, you should set should_poll
to False
on the entities.
ENTITY_ID_FORMAT, device_id, hass=hass) | ||
self._config = config | ||
self._name = name | ||
self._value = None |
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 doesn't seem to be used, only assigned.
"""Return the name of the sensor.""" | ||
return self._name | ||
|
||
def update(self, *args): |
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.
Remove this if you don't need it.
def __init__(self, hass, lacrosse, device_id, name, expire_after, config): | ||
"""Initialize the sensor.""" | ||
self.hass = hass | ||
self.entity_id = async_generate_entity_id( |
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.
You should not use the async version of the function, since it will be called from within a thread. Just use generate_entity_id
instead.
self._expire_after = expire_after | ||
self._expiration_trigger = None | ||
|
||
lacrosse.register_callback( |
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.
It might be safer to move the registering of the callback into the coroutine method async_added_to_hass
that you can define on the entity. Reason is you need access to the hass
object in the callback.
Signed-off-by: Heiko Thiery [email protected]
Description:
Pull request in home-assistant.github.io with documentation: home-assistant/home-assistant.io#3829
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.