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

Support for Home Assistant > 0.96 #13

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file removed Capture.PNG
Binary file not shown.
Binary file removed Capture2.PNG
Binary file not shown.
30 changes: 21 additions & 9 deletions README.md
Expand Up @@ -4,33 +4,45 @@ This is a platform to support Fujitsu General Airconditioners under Climate comp

### Sample UI:

![UI_SCREENSHOT](https://github.com/Mmodarre/pyfujitsu_for_homeassistant/blob/master/Capture.PNG)
![UI_SCREENSHOT](https://github.com/Mmodarre/pyfujitsu_for_homeassistant/blob/master/Capture2.PNG)
![UI_SCREENSHOT](https://raw.githubusercontent.com/xerxes87/pyfujitsu_for_homeassistant/master/ha_fujitsu.jpg)

### Usage:
1. create this directory path `/config/custom_components/fujitsu_general_heatpump/` if it does not already exist.


2. Download the `fujitsu_general_heatpump.py` `manifest.json' and 'init.py` from the repo and place it in the directory mentioned in previous step. Rename `fujitsu_general_heatpump.py` to `climate.py`
2. Download the `climate.py` `manifest.json' and '__init__.py` from the repo and place it in the directory mentioned in previous step.

So the end result would look like:
`/config/custom_components/fujitsu_general_heatpump/climate.py`
`/config/custom_components/fujitsu_general_heatpump/manifest.json`
`/config/custom_components/fujitsu_general_heatpump/init.py`
`/config/custom_components/fujitsu_general_heatpump/__init__.py`

3. add the below lines to your `configuration.yaml` file and replace it with your FGLair app username/password:
```
climate:
- platform: fujitsu_general_heatpump
username: <your FGLair username>
password: <your FGLair password>
region: [eu, cn, us] (optional, default: us)
tokenpath: (optional, default: 'token.txt')
```

Full Example:
```
climate:
- platform: fujitsu_general_heatpump
username: !secret FGLAIR_USER
password: !secret FGLAIR_PASS
region: 'eu'
tokenpath: 'token.txt'
```

4. Restart Home Assistant in order for the new component to show and all of your A/Cs in your account should appear in HASS.

### Known issues and missing features:

[RESOLVED]1. Google Assistant integration is not working [most possibly due to states not matching what Google assistant is expecting]
2. Logging needs to be implemented
3. The “powerful” functionality is implemented through aux_heat button in UI
4. There are some other functionalities in the A/C which currently is not implemented.
5. Could not reverse engineer the API to give the ambient room temperature. If you figured it out let me know and I am happy to update the library.

- [X] Logging needs to be implemented
- [ ] The “powerful” functionality is implemented through aux_heat button in UI
- [ ] There are some other functionalities in the A/C which currently is not implemented.
- [ ] Possibility to add external temerature sensor
1 change: 1 addition & 0 deletions custom_components/fujitsu_general_heatpump/__init__.py
@@ -0,0 +1 @@
""" fujitsu_general_heatpump integration."""
242 changes: 242 additions & 0 deletions custom_components/fujitsu_general_heatpump/climate.py
@@ -0,0 +1,242 @@
"""
Support for the Fujitsu General Split A/C Wifi platform AKA FGLair .
"""

import logging
import voluptuous as vol
from pyfujitseu.api import Api as fgapi
from pyfujitseu.splitAC import splitAC


from homeassistant.components.climate import ClimateEntity, PLATFORM_SCHEMA
from homeassistant.components.climate.const import (
HVAC_MODE_OFF,
HVAC_MODE_HEAT,
HVAC_MODE_COOL,
HVAC_MODE_AUTO,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
SUPPORT_FAN_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_AUX_HEAT,
FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_DIFFUSE,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE)
from homeassistant.const import (
ATTR_TEMPERATURE, CONF_USERNAME, CONF_PASSWORD, TEMP_CELSIUS)
import homeassistant.helpers.config_validation as cv

__version__ = '0.9.1'



_LOGGER = logging.getLogger(__name__)

#REQUIREMENTS = ['pyfujitseu==0.9.3.2']

# Values from web interface
MIN_TEMP = 16
MAX_TEMP = 30

SUPPORT_FLAGS = SUPPORT_FAN_MODE | SUPPORT_SWING_MODE | SUPPORT_TARGET_TEMPERATURE

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional('region'): cv.string,
vol.Optional('tokenpath'): cv.string,

})


HA_FAN_TO_FUJITSU = {
FAN_AUTO: "Auto",
FAN_LOW: "Low",
FAN_MEDIUM: "Medium",
FAN_HIGH: "High",
FAN_DIFFUSE: "Quiet"
}

FUJITSU_FAN_TO_HA = {
"Auto": FAN_AUTO,
"Low": FAN_LOW,
"Medium": FAN_MEDIUM,
"High": FAN_HIGH,
"Quiet": FAN_DIFFUSE
}


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Setup the E-Thermostaat Platform."""

_LOGGER.debug("FujitsuClimate setup_platform called")
_LOGGER.debug("FujitsuClimate setup_platform called")

username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
region = config.get('region')
tokenpath = config.get('tokenpath')
_LOGGER.debug("FujitsuClimate config.get ")

fglairapi = fgapi(username, password, region, tokenpath)
if not fglairapi._authenticate():
_LOGGER.error("Unable to authenticate with Fujistsu General")
return

_LOGGER.debug("FujitsuClimate fglairapi._authenticate ")

devices = fglairapi.get_devices_dsn()
add_entities(FujitsuClimate(fglairapi, dsn) for dsn in devices)
_LOGGER.debug("FujitsuClimate setup_platform fine")


class FujitsuClimate(ClimateEntity):
"""Representation of a E-Thermostaat device."""

def __init__(self, api, dsn):
"""Initialize the thermostat."""
_LOGGER.debug("FujitsuClimate init called for dsn: %s", dsn)
_LOGGER.debug("FujitsuClimate pyfujitseu.splitAC called")
self._api = api
self._dsn = dsn
self._fujitsu_device = splitAC(self._dsn, self._api)
_LOGGER.debug("FujitsuClimate _fujitsu_device setup.")
self._name = self.name
_LOGGER.debug("FujitsuClimate name set: %s", self._name)
self._aux_heat = self.is_aux_heat_on
self._target_temperature = self.target_temperature
self._fan_mode = self.fan_mode
self._hvac_mode = self.hvac_mode
self._swing_mode = self.swing_mode

self._fan_modes = [FUJITSU_FAN_TO_HA['Quiet'], FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO]
self._hvac_modes = [HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_AUTO, HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_OFF]
self._swing_modes = ['Horizontal' ,'Down', 'Unknown', 'Swing' ]
self._on = self.is_on


_LOGGER.debug("FujitsuClimate init fine.")

@property
def name(self):
"""Return the name of the thermostat."""
return self._fujitsu_device.device_name['value']

@property
def is_aux_heat_on(self):
"""Reusing is for Powerfull mode."""
if not hasattr(self._fujitsu_device.powerful_mode, 'value'):
return False
elif self._fujitsu_device.powerful_mode['value'] == 1:
return True
else:
return False

@property
def target_temperature(self):
"""Return the temperature we try to reach."""
return self._fujitsu_device.adjust_temperature_degree

@property
def target_temperature_step(self):
"""Return the supported step of target temperature."""
return 1


@property
def is_on(self):
"""Return true if on."""
if self._fujitsu_device.operation_mode['value'] != 0:
return True
else:
return False

@property
def hvac_mode(self):
"""Return current operation ie. heat, cool, idle."""
_LOGGER.debug("FujitsuClimate hvac_mode: %s", self._fujitsu_device.operation_mode['value'])
return self._fujitsu_device.operation_mode_desc

@property
def hvac_modes(self):
"""HVAC modes."""
return self._hvac_modes

def set_hvac_mode(self, hvac_mode):
"""Set HVAC mode."""
_LOGGER.debug("FujitsuClimate set_hvac_mode called. self._hvac_mode: %s ; hvac_mode: %s", self._hvac_mode, hvac_mode)
if(hvac_mode == HVAC_MODE_OFF):
self._fujitsu_device.turnOff()
elif(self._hvac_mode != hvac_mode):
_LOGGER.debug("FujitsuClimate set_hvac_mode elif path called. ")
self._fujitsu_device.changeOperationMode(hvac_mode)

def set_temperature(self, **kwargs):
"""Set new target temperature."""
_LOGGER.debug("FujitsuClimate set_temperature: %s ; 2: %s", kwargs.get(ATTR_TEMPERATURE), kwargs.get(ATTR_TEMPERATURE))
self._fujitsu_device.changeTemperature(kwargs.get(ATTR_TEMPERATURE))

def update(self):
"""Retrieve latest state."""
self._fujitsu_device.refresh_properties()

@property
def fan_mode(self):
"""Return the fan setting."""
return FUJITSU_FAN_TO_HA[self._fujitsu_device.get_fan_speed_desc()]

@property
def fan_modes(self):
"""Return the list of available fan modes."""
return self._fan_modes

def set_fan_mode(self, fan_mode):
"""Set fan mode."""
self._fujitsu_device.changeFanSpeed(HA_FAN_TO_FUJITSU[fan_mode])

@property
def swing_mode(self):
"""Return the fan setting."""
return self._fujitsu_device.get_swing_mode_desc()

@property
def swing_modes(self):
"""List of available swing modes."""
return self._swing_modes

def set_swing_mode(self, swing_mode):
"""Set new target temperature."""
self._fujitsu_device.changeSwingMode(swing_mode)

############old stufffff

@property
def unique_id(self) -> str:
"""Return the unique ID for this thermostat."""
return '_'.join([self._name, 'climate'])

@property
def should_poll(self):
"""Polling is required."""
return True

@property
def min_temp(self):
"""Return the minimum temperature."""
return MIN_TEMP

@property
def max_temp(self):
"""Return the maximum temperature."""
return MAX_TEMP

@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS
12 changes: 12 additions & 0 deletions custom_components/fujitsu_general_heatpump/manifest.json
@@ -0,0 +1,12 @@
{
"domain": "fujitsu_general_heatpump",
"name": "Fujitsu general heatpump",
"documentation": "https://github.com/Mmodarre/pyfujitsu_for_homeassistant/blob/master/README.md",
"requirements": ["pyfujitseu"],
"dependencies": [],
"codeowners": [
"@Mmodarre",
"@xerxes87"
],
"version": "1.0.0"
}