GladysProject/Gladys

View on GitHub

Showing 2,674 of 2,674 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  <DndProvider backend={isTouchDevice ? TouchBackend : HTML5Backend}>
    {selectedDeviceFeaturesOptions.map((selectedDeviceFeature, index) => (
      <DeviceRow
        selectedDeviceFeature={selectedDeviceFeature}
        updateDeviceFeatureName={updateDeviceFeatureName}
front/src/routes/integration/all/lan-manager/settings-page/LANManagerIPRange.jsx on lines 54..64

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  closeTagFilterDropdown = e => {
    if (this.dropdownRef && this.dropdownRef.contains(e.target)) {
      return;
    }
    this.setState({ tagFilterDropdownOpened: false });
Severity: Major
Found in front/src/routes/scene/SceneTagFilter.jsx and 1 other location - About 1 hr to fix
front/src/routes/scene/edit-scene/SceneActionsDropdown.jsx on lines 22..27

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

              <tbody>
                {ipMasks.map((mask, maskIndex) => (
                  <LANManagerIPLine
                    ipMask={mask}
                    disabled={disabled}
front/src/components/boxs/device-in-room/DeviceListWithDragAndDrop.jsx on lines 84..94

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 60.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function EdfTempoService has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function EdfTempoService(gladys, serviceId) {
  const dayjs = require('dayjs');
  const axios = require('axios').default;
  const utc = require('dayjs/plugin/utc');
  const timezone = require('dayjs/plugin/timezone');
Severity: Minor
Found in server/services/edf-tempo/index.js - About 1 hr to fix

    Function convertFeature has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function convertFeature(tuyaFunctions, externalId) {
      const { code, values, name, readOnly } = tuyaFunctions;
    
      const featuresCategoryAndType = mappings[code];
      if (!featuresCategoryAndType) {
    Severity: Minor
    Found in server/services/tuya/lib/device/tuya.convertFeature.js - About 1 hr to fix

      Function poll has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function poll(device) {
        const externalId = device.external_id;
        const [prefix, topic] = device.external_id.split(':');
      
        if (prefix !== 'melcloud') {
      Severity: Minor
      Found in server/services/melcloud/lib/melcloud.poll.js - About 1 hr to fix

        Function onReportState has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function onReportState(body) {
          const deviceSelector = get(body, 'directive.endpoint.endpointId');
          const device = this.gladys.stateManager.get('device', deviceSelector);
          if (!device) {
            throw new NotFoundError(`Device "${deviceSelector}" not found`);
        Severity: Minor
        Found in server/services/alexa/lib/alexa.onReportState.js - About 1 hr to fix

          Function checkBatteries has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          async function checkBatteries() {
            const enabled = await this.variable.getValue(SYSTEM_VARIABLE_NAMES.DEVICE_BATTERY_LEVEL_WARNING_ENABLED);
            if (!enabled) {
              return;
            }
          Severity: Minor
          Found in server/lib/device/device.checkBatteries.js - About 1 hr to fix

            Function add has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function add(device) {
              this.stateManager.setState('device', device.selector, device);
              this.stateManager.setState('deviceByExternalId', device.external_id, device);
              this.stateManager.setState('deviceById', device.id, device);
              device.features.forEach((feature) => {
            Severity: Minor
            Found in server/lib/device/device.add.js - About 1 hr to fix

              Function login has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  async login(state, e) {
                    if (e) {
                      e.preventDefault();
                    }
                    if (!validateEmail(state.loginFormEmailValue)) {
              Severity: Minor
              Found in front/src/actions/login/login.js - About 1 hr to fix

                Function componentWillMount has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  async componentWillMount() {
                    let { deviceSelector } = this.props;
                    let device;
                
                    await Promise.all([this.props.getIntegrationByName(this.props.integrationName), this.props.getHouses()]);
                Severity: Minor
                Found in front/src/components/device/index.js - About 1 hr to fix

                  Function render has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    render(props) {
                      return (
                        <div class="row g-2 mb-2">
                          <div class="col-5">
                            <Localizer>
                  Severity: Minor
                  Found in front/src/routes/scene/edit-scene/actions/HttpRequest.jsx - About 1 hr to fix

                    Function render has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      render(props, { selectedDeviceFeaturesOptions, deviceOptions, loading, room }) {
                        const roomName = room && room.name;
                        return (
                          <BaseEditBox {...props} titleKey="dashboard.boxTitle.devices-in-room" titleValue={roomName}>
                            <div class={loading ? 'dimmer active' : 'dimmer'}>
                    Severity: Minor
                    Found in front/src/components/boxs/device-in-room/EditDeviceInRoom.jsx - About 1 hr to fix

                      Function createDevice has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      const createDevice = (networkAddress, serviceId, username, password) => {
                        const externalId = `tasmota:${networkAddress}`;
                        const device = {
                          name: networkAddress,
                          external_id: externalId,
                      Severity: Minor
                      Found in server/services/tasmota/lib/http/tasmota.http.status.js - About 1 hr to fix

                        Function scanPresence has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        async function scanPresence() {
                          const devices = await this.gladys.device.get({
                            service: 'lan-manager',
                            device_feature_category: DEVICE_FEATURE_CATEGORIES.PRESENCE_SENSOR,
                          });
                        Severity: Minor
                        Found in server/services/lan-manager/lib/lan-manager.scanPresence.js - About 1 hr to fix

                          Function up has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            up: async (queryInterface, Sequelize) => {
                              await queryInterface.createTable('t_device_feature_state', {
                                id: {
                                  allowNull: false,
                                  primaryKey: true,
                          Severity: Minor
                          Found in server/migrations/20190211041243-create-device-feature-state.js - About 1 hr to fix

                            Function WeatherController has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            module.exports = function WeatherController(gladys) {
                              /**
                               * @api {get} /api/v1/user/:user_selector/weather get weather user
                               * @apiName getWeatherUser
                               * @apiGroup Weather
                            Severity: Minor
                            Found in server/api/controllers/weather.controller.js - About 1 hr to fix

                              Function associate has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                User.associate = (models) => {
                                  User.hasMany(models.Location, {
                                    foreignKey: 'user_id',
                                    sourceKey: 'id',
                                    as: 'locations',
                              Severity: Minor
                              Found in server/models/user.js - About 1 hr to fix

                                Function transformDevice has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                function transformDevice(device) {
                                  const { mac, hostname, ip, vendor } = device;
                                  const deviceExternalId = `lan-manager:${mac.replaceAll(':', '').toLowerCase()}`;
                                
                                  const params = [];
                                Severity: Minor
                                Found in server/services/lan-manager/lib/lan-manager.transformDevice.js - About 1 hr to fix

                                  Function downloadBackup has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  async function downloadBackup(fileUrl) {
                                    const encryptKey = await this.variable.getValue('GLADYS_GATEWAY_BACKUP_KEY');
                                    if (encryptKey === null) {
                                      throw new NotFoundError('GLADYS_GATEWAY_BACKUP_KEY_NOT_FOUND');
                                    }
                                  Severity: Minor
                                  Found in server/lib/gateway/gateway.downloadBackup.js - About 1 hr to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language