Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 17 commits into from
Nov 3, 2017
Merged

Add LaCrosse sensor platform #10195

merged 17 commits into from
Nov 3, 2017

Conversation

hthiery
Copy link
Contributor

@hthiery hthiery commented Oct 28, 2017

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):

sensor:
  - platform: lacrosse
    sensors:
      wohnzimmer_temperature:
        friendly_name: Wohnzimmer Temperatur
        type: temperature
        id: 60
      wohnzimmer_humidity:
        friendly_name: Wohnzimmer Luftfeuchtigkeit
        type: humidity
        id: 60
      wohnzimmer_battery:
        friendly_name: Wohnzimmer Sensor Batterie
        type: battery
        id: 60

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

@homeassistant
Copy link
Contributor

Hi @hthiery,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

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

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):

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)

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)

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):

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):

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:

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):

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

@homeassistant
Copy link
Contributor

Hi @hthiery,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

self._expiration_trigger = None

lacrosse.register_callback(int(self._config["id"]), \
self._callback_lacrosse, None)

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"]), \

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, \

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):

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, \

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]>
@hthiery hthiery changed the title Initial commit of LaCrosse sensor component Add LaCrosse sensor component Oct 29, 2017
Signed-off-by: Heiko Thiery <[email protected]>



class LaCrosseSensor(Entity):

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]>
@hthiery
Copy link
Contributor Author

hthiery commented Oct 29, 2017

Currently I cannot figure out why build fails. Has anyone an idea?

Signed-off-by: Heiko Thiery <[email protected]>
@fabaff fabaff changed the title Add LaCrosse sensor component Add LaCrosse sensor platform Oct 30, 2017
def state(self):
"""Return the state of the sensor."""
if self._low_battery is None:
state = 'na/a'
Copy link
Member

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 = {
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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)
Copy link
Member

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,
Copy link
Member

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,
Copy link
Member

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'
Copy link
Member

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."""
Copy link
Member

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)
Copy link
Member

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.

@home-assistant home-assistant deleted a comment from houndci-bot Oct 31, 2017
@hthiery
Copy link
Contributor Author

hthiery commented Nov 2, 2017

Do I need to add tests for the PR?

@fabaff
Copy link
Member

fabaff commented Nov 2, 2017

You could if you want. It's not a requirement as you depend on a module and often the module itself contains already tests.

@hthiery
Copy link
Contributor Author

hthiery commented Nov 2, 2017

Ok that means I can remove the checkbox for tests from the checklist?

@fabaff
Copy link
Member

fabaff commented Nov 2, 2017

Oh, you were talking about the local tox tests. We run tox on the Pull requests automatically. If a local tests fails the chances are high that it will fails here too.

Copy link
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 🐦

@fabaff fabaff merged commit 23809bf into home-assistant:dev Nov 3, 2017
Copy link
Member

@MartinHjelmare MartinHjelmare left a 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
Copy link
Member

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):
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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.

@balloob balloob mentioned this pull request Nov 17, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Mar 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants