Skip to content
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

Miflora #3053

Merged
merged 23 commits into from Sep 14, 2016
Merged

Miflora #3053

merged 23 commits into from Sep 14, 2016

Conversation

ghost
Copy link

@ghost ghost commented Aug 30, 2016

Description: Support for Mi Flora plant sensor

Related issue (if applicable): fixes #

Pull request in home-assistant.io with documentation (if applicable): not yet done

Example entry for configuration.yaml (if applicable):

sensor
  platform: miflora
  mac: xx:xx:xx:xx:xx:xx
  name: Flower 1
  force_update: false
  median: 3
  monitored_conditions:
   - moisture
   - light
   - temperature
   - conductivity

Checklist:

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

If code communicates with devices, web services, or a:

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

return self._unit

@property
def force_update(self):

Choose a reason for hiding this comment

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

farcy v1.1

  • D400: First line should end with a period (not 'e')

Copy link
Author

Choose a reason for hiding this comment

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

This has been fixed, but it seems that this comment isn't updated automatically.

Copy link
Contributor

Choose a reason for hiding this comment

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

Farcy comments on the method definition - your code change is the line below - it's a terrible little bot, has bunch of bugs. Don't worry about it :-)

Daniel Matuschek and others added 2 commits August 30, 2016 07:19

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_MAC): cv.string,
vol.Required(CONF_MONITORED_CONDITIONS, default=[]):
Copy link
Member

Choose a reason for hiding this comment

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

'default' is unnecessary when the option is required.

Copy link
Author

Choose a reason for hiding this comment

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

Ok

self.data.append(data)
else:
LOGGER.debug("Did not receive any data for %s", self.name)

Copy link
Member

Choose a reason for hiding this comment

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

Should there be a 'return' here?

Copy link
Author

Choose a reason for hiding this comment

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

It's not necessary as update won't change anything in this case. But I can add a return, it doesn't hurt.

@Danielhiversen
Copy link
Member

Would it be possible to support several sensors?

@ghost
Copy link
Author

ghost commented Aug 30, 2016

Yes, you can just define multiple sensors in the configuration. Every sensor has a different MAC address.

@Danielhiversen
Copy link
Member

Have you tested with multiple sensors?

@ghost
Copy link
Author

ghost commented Aug 30, 2016

No, I only have a single sensor here (waiting for more to be delivered), but I don't see any reason why it shouldn't work with multiple sensors.

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=900)
CONF_MAC = "mac"
CONF_FORCE_UPDATE = 'force_update'
DEFAULT_NAME = ""
Copy link
Member

Choose a reason for hiding this comment

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

How about DEFAULT_NAME = "Mi Flora"?

Copy link
Author

Choose a reason for hiding this comment

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

If no default is given, the name is retrieved from the device itself. Personally, I like this more than a hard-coded default name.
However, if you're have more than a single plant and your using more than a single sensor, you will usually configure a new for each of them anyway.

Copy link
Member

Choose a reason for hiding this comment

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

So, DEFAULT_NAME would not be needed at all and instead doing the test for an empty string it could be done against None.

Copy link
Author

Choose a reason for hiding this comment

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

That's right. I will change this.

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking about this again. Reading the name from the sensor during initialization isn't a good idea when the sensors temporary isn't available. Therefore I have changed the code name to use a hard-coded default name. (The name in the sensor is usually also always the same, therefore it doesn't help to differentiate between sensors).


LOGGER = logging.getLogger(__name__)
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=900)
CONF_MAC = "mac"
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixing ' and "

@Teagan42
Copy link
Contributor

You will need to add unit test or add the files to .coveragerc - tests are much preferred.

@Teagan42
Copy link
Contributor

Unrelated - I wish I knew about these a few months ago when I started my indoor garden. Maybe next go round :-)

@ghost
Copy link
Author

ghost commented Aug 31, 2016

Units tests can't be implemented here as this would not only require a Linux system with a Bluetooth stack but also a working sensor. Both isn't available on the test system.

@Teagan42
Copy link
Contributor

Then you need to add the files to .coveragerc

On Aug 30, 2016 10:38 PM, "Open Home Automation" notifications@github.com
wrote:

Units tests can't be implemented here as this would not only require a
Linux system with a Bluetooth stack but also a working sensor. Both isn't
available on the test system.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#3053 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC2fZf3VR_Ei4UJ5x1DupmC65T2UVQyCks5qlQU9gaJpZM4JwJvn
.

@ghost
Copy link
Author

ghost commented Aug 31, 2016

The sensor file is already added to .coveragerc

@Teagan42
Copy link
Contributor

Fuck I'm tired - totally missed it.

On Tue, Aug 30, 2016 at 10:49 PM, Open Home Automation <
notifications@github.com> wrote:

The sensor file is already added to .coveragerc


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#3053 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC2fZYPuA-KMZnX-ZWXsseBKRy-U-Glkks5qlQfSgaJpZM4JwJvn
.

@Teagan42
Copy link
Contributor

So the only real issue is the mixing of quotes.

@property
def unit_of_measurement(self):
"""Return the units of measurement."""
return self._unit
Copy link
Contributor

Choose a reason for hiding this comment

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

If the HASS configured unit system is imperial , we should be doing a conversion from C to F (both unit of measurement and state properties)

@Danielhiversen
Copy link
Member

Is this ready to merge now?

@ghost
Copy link
Author

ghost commented Sep 12, 2016

@Danielhiversen From my point of view it is ready to merge.

@Danielhiversen Danielhiversen added this to the 0.29 milestone Sep 13, 2016
@balloob
Copy link
Member

balloob commented Sep 14, 2016

Looks good! 🐬

@balloob balloob merged commit 0c7c85d into home-assistant:dev Sep 14, 2016
hartmms pushed a commit to hartmms/home-assistant that referenced this pull request Sep 17, 2016
* First version of the MiFlora sensor (not yet finished)

* First workign version

* Added some documentation
Get name from sensor, if not defined

* Ignore IOError

* Added force_update option

* Updated comments

* Renamed fertility to conductivity (what it really is)

* MiFlora library update

* Updated helper files

* Formatting

* Fixed pylint errors

* Removed default from monitored conditions

* Removed KeyError handling as a KeyError should never be raised

* Added a return when no data is received

* emoved unnecessary return statement

* Changed default name

* Changes quotes and string operation ( @Teagan42 )

* - number of samples for median calculation is now configurable
- set state to None if no data could be polled from sensor

* Bugfix in library
more logging

* Fixed miflora version number
@lwis
Copy link
Member

lwis commented Sep 19, 2016

@open-homeautomation could you add the website docs for this, please?

@ghost
Copy link
Author

ghost commented Sep 19, 2016

Yes, I will work on this.

@ghost
Copy link
Author

ghost commented Sep 19, 2016

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

Successfully merging this pull request may close these issues.

8 participants