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

Add support for more sensors & basic Siren (switch) support #84

Merged
merged 44 commits into from
Jul 6, 2020

Conversation

iMicknl
Copy link
Owner

@iMicknl iMicknl commented Jun 22, 2020

Added

  • Added initial support for AirFlowSensor
  • Added initial support for WaterDetectionSensor
  • Added support for RainSensor
  • Added support for CarButtonSensor
  • Added basic support for Siren as switch
  • Added support for MotionSensor
  • Added support for SunSensor
  • Added support for WindSensor
  • Added all available states to device state attributes
  • Added support for COSensor and CO2Sensor (AirSensor)

Changed

  • Change 'battery_level' attribute to an integer, estimated based on the battery state
  • Changed CO2Sensor device class to co2 to show as co2 sensor in HomeKit
  • Remove tahoma_scene_oid, which is already used as unique_id for scenes

Copy link
Collaborator

@vlebourl vlebourl left a comment

Choose a reason for hiding this comment

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

None of my comments are game changing. feel free to ignore if you disagree.

CHANGELOG.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
custom_components/tahoma/binary_sensor.py Outdated Show resolved Hide resolved
custom_components/tahoma/binary_sensor.py Show resolved Hide resolved
"{:.2f}".format(
self.tahoma_device.active_states.get(CORE_RELATIVE_HUMIDITY_STATE)
)
"{:.2f}".format(states.get(CORE_RELATIVE_HUMIDITY_STATE))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use f-strings here. I think this will be required for a merge in core.
f'{states.get(CORE_RELATIVE_HUMIDITY_STATE):%.2f}'

Copy link
Owner Author

Choose a reason for hiding this comment

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

@tetienne do we need fstrings for all floats here? home-assistant/core#36258 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you have in entry and what do you want in output?

To have a float from a string you can do:

>>>a = "2.3"
>>>float(a)
2.3

Copy link
Collaborator

Choose a reason for hiding this comment

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

do we actually convert a float to string then to float?

Copy link
Owner Author

Choose a reason for hiding this comment

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

To be honest, I am not sure how HA would like to have the values. Do they require a float or is a floating value in a string the right approach?

In the end, what should happen in sensor.py is that we make round the value and make it an int or float.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@vlebourl, is states.get(CORE_RELATIVE_HUMIDITY_STATE) already a float? If a string, the round method can not be applied.

>>> a = "2.3"
>>> round(a, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type str doesn't define __round__ method

Copy link
Collaborator

@vlebourl vlebourl Jul 6, 2020

Choose a reason for hiding this comment

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

I think it. otherwise we would get

>>> a = "2.3"
>>> "{:.2f}".format(a)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: Unknown format code 'f' for object of type 'str'

Copy link
Collaborator

Choose a reason for hiding this comment

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

And that's the signature for my temperature sensor:
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's maybe leave this like this for now as this PR is already quite large, but resolve this in another PR once this one is merged

Copy link
Owner Author

Choose a reason for hiding this comment

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

Agree, let's work on those improvements in separate smaller PR's. This one already got way to big :D

custom_components/tahoma/switch.py Show resolved Hide resolved
custom_components/tahoma/switch.py Show resolved Hide resolved
@tetienne
Copy link
Collaborator

tetienne commented Jul 6, 2020

Not related to the code, but I highly recommand you do only squash and merge your PR. You will have a nice commit history in the master branch without all your WIP and Fix commit of your branch.
Many projects do like this, HA included.

@iMicknl
Copy link
Owner Author

iMicknl commented Jul 6, 2020

Not related to the code, but I highly recommand you do only squash and merge your PR. You will have a nice commit history in the master branch without all your WIP and Fix commit of your branch.
Many projects do like this, HA included.

Makes sense. Especially since this PR doesn't include a nice commit log. 👍

@tetienne
Copy link
Collaborator

tetienne commented Jul 6, 2020

Not related to the code, but I highly recommand you do only squash and merge your PR. You will have a nice commit history in the master branch without all your WIP and Fix commit of your branch.
Many projects do like this, HA included.

Makes sense. Especially since this PR doesn't include a nice commit log. +1

You got it. You can allow only this method if you want in the settings of your repository.

"{:.2f}".format(
self.tahoma_device.active_states.get(CORE_RELATIVE_HUMIDITY_STATE)
)
"{:.2f}".format(states.get(CORE_RELATIVE_HUMIDITY_STATE))
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we actually convert a float to string then to float?

@vlebourl
Copy link
Collaborator

vlebourl commented Jul 6, 2020

Shall we merge?

@iMicknl iMicknl changed the title Add more sensor support & basic Siren switch support Add support for more sensors & basic Siren (switch) support Jul 6, 2020
@iMicknl iMicknl merged commit dd3a5c6 into master Jul 6, 2020
@iMicknl iMicknl deleted the refactor_sensor branch July 6, 2020 12:53
@tetienne
Copy link
Collaborator

Exemple of water sensor

{
      "typeId": 131,
      "subsystemId": 0,
      "localPairing": false,
      "states": [
        {
          "name": "SensorDefectState",
          "type": "DiscreteState",
          "eventBased": false,
          "persistent": false
        },
        {
          "name": "WaterDetectionState",
          "type": "DiscreteState",
          "eventBased": true,
          "persistent": false,
          "prototype": {
            "valuePrototypes": [
              {
                "type": "STRING",
                "enumValues": [
                  "detected",
                  "notDetected"
                ],
                "description": "string value (detected, notDetected)"
              }
            ]
          }
        }
      ],
      "attributes": [
        {
          "name": "core:PowerSourceType",
          "type": 3,
          "defaultValue": "battery"
        }
      ],
      "controllableName": "rtds:RTDSWaterSensor",
      "uiClass": "HumiditySensor",
      "uiProfiles": [
        "WaterDetector"
      ],
      "uiWidget": "WaterDetectionSensor",
      "controllableType": "SENSOR",
      "protocolType": "RTDS"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for RainSensor (io:SomfyRainIOSystemSensor)
3 participants