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

Modbus sensor refactoring #3297

Merged
merged 1 commit into from
Sep 13, 2016
Merged

Modbus sensor refactoring #3297

merged 1 commit into from
Sep 13, 2016

Conversation

persandstrom
Copy link
Contributor

@persandstrom persandstrom commented Sep 9, 2016

Description:
The modbus sensor needed some love.

I have:

  • Moved the coil support to binary_sensor, since it is a 1-bit value.
  • Removed the bits part of the sensor register config, since this can be done more efficient with a template_sensor.
  • Removed the register support from the switch since it can be done with template_switch.
  • Removed unused functions and unnecessary overrides.
  • Moved the slave attribute to each register so that it's easier to communicate with several slaves.
  • Changed the registers and coils attributes from a dicts to lists.
  • Added a length attribute to the register sensor.
  • Changed from unit attribute to the more commonly used unit_of_measurement
  • Added voluptuous to all modbus components

I will add voluptuous in the next PR

I have not been able to test the binary_sensor or switch since my unit lacks coils, if anyone has a unit with coils I would appreciate some help!

Related issue (if applicable): fixes #
#3038

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#
home-assistant/home-assistant.io#933

Example entry for configuration.yaml (if applicable):

modbus:                                                                                                         
  type: serial                                                                                                  
  method: rtu                                                                                                   
  port: /dev/ttyUSB0                                                                                            
  baudrate: 9600                                                                                                
  stopbits: 1                                                                                                   
  bytesize: 8                                                                                                   
  parity: N   

sensor:                                                                                                                        
  - platform: modbus                                                             
    registers:                                                                   
      - name: Fan Speed                                                          
        slave: 1                                                                 
        register: 100                                                            
      - name: Temperature set                                                    
        slave: 1                                                                 
        register: 206                                                            
      - name: Supply air                                                         
        unit_of_measurement: °C                                                  
        slave: 1                                                                 
        register: 213                                                            
        scale: 0.1                                                               
        precision: 1                                                             
      - name: Extract air                                                        
        unit_of_measurement: °C                                                  
        slave: 1                                                                 
        register: 214                                                            
        scale: 0.1                                                               
        precision: 1

binary_sensor:
  - platform: modbus
    coils:
      - name: Alarm 1
        slave: 2
        coil: 15

switch:
  - platform: modbus
    coils:
      - name: Heater
        slave: 1
        coil: 2

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

@hoopty
Copy link
Contributor

hoopty commented Sep 10, 2016

Any chance this can make it into .28?

add_devices(sensors)


class ModbusCoilSensor(Entity):
Copy link
Member

Choose a reason for hiding this comment

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

Use BinarySensor instead Entity. See on other binary sensors.

@persandstrom
Copy link
Contributor Author

The switch is still to be done. Not ready for merge yet

@persandstrom
Copy link
Contributor Author

The refactoring is done, except for fixes for future review comments.

@fabaff fabaff mentioned this pull request Sep 12, 2016
vol.Required(CONF_BAUDRATE): cv.positive_int,
vol.Required(CONF_BYTESIZE): vol.Any(5, 6, 7, 8),
vol.Required(CONF_METHOD): vol.Any('rtu', 'ascii'),
vol.Required(CONF_PORT): str,
Copy link
Member

Choose a reason for hiding this comment

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

For the sake of consistency -> cv.string

@kellerza
Copy link
Member

Looks good overall, but I do not have any Modbus kit though. Would be nice if someone can help test it, but as long as the upstream library supports binary_sensor and switch I guess it should be ok

@persandstrom
Copy link
Contributor Author

I found a modbus slave simulation tool, I can do some simple tests with that.

@persandstrom
Copy link
Contributor Author

Managed to find a bug from pre-refactoring with the test tool (http://www.modbusdriver.com/diagslave.html). binary_sensor and switch are tested and works

@kellerza
Copy link
Member

Looks good! 🐬

@kellerza kellerza merged commit ca646c0 into home-assistant:dev Sep 13, 2016
@persandstrom persandstrom deleted the modbus_sensor_refactoring branch September 13, 2016 20:59
hartmms pushed a commit to hartmms/home-assistant that referenced this pull request Sep 17, 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.

5 participants